小编O.T*_*.T.的帖子

在MATLAB中重载函数

我想在MATLAB中修改一个计算给定公式的代码,我想用与给定公式中相同的符号编写代码.在公式中,我有两个不同的函数,它们具有相同的名称,但只有参数的数量不同:Kn(a,b)Kn(a).

MATLAB中有没有一种方法可以像c ++一样定义重载函数?

matlab overloading

3
推荐指数
1
解决办法
3295
查看次数

如何通过围绕其中心元素旋转一维数字向量来创建二维图像?

我有一个一维数字向量,它代表圆形对称物体的中心切割。向量本身围绕其中心元素对称。我想在 MATLAB 中通过围绕其中心元素旋转 1D 向量来创建原始对象的 2D 图像。

我尝试了以下代码(使用数字的虚拟原始向量),但是从生成的 2D 图像中获得的中心切割与原始 1D 向量不匹配,如果运行代码就可以看到。我将不胜感激任何帮助!

close all; clc    

my1D_vector=[ zeros(1,20) ones(1,15) zeros(1,20)]; % original vector

len=length(my1D_vector);    
img=zeros(len, len);
thetaVec=0:0.1:179.9; % angles through which to rotate the original vector  
numRotations=length(thetaVec);

% the coordinates of the original vector and the generated 2D image:
x=(1:len)-(floor(len/2)+1);  
y=x;

[X,Y]=meshgrid(x,y);

for ind_rotations=1:numRotations
    theta=pi/180*thetaVec(ind_rotations);
    t_theta=X.*cos(theta)+Y.*sin(theta);        
    cutContrib=interp1(x , my1D_vector , t_theta(:),'linear');
    img=img+reshape(cutContrib,len,len);
end
img=img/numRotations;

figure('name','original vector');plot(x,my1D_vector,'b.-')
figure('name','generated 2D image');  imagesc(x,y,img); colormap(gray) ; 

figure('name','comparison between the original vector and a center cut …
Run Code Online (Sandbox Code Playgroud)

matlab image-processing rotation

2
推荐指数
1
解决办法
2350
查看次数

如何在3D MATLAB矩阵中找到最大元素的位置?

我有一个尺寸为100*10*1344的3D matlab矩阵.

我想找到矩阵的最大元素的三个索引.

当我尝试使用命令find找到它时,我得到:

>> [i j k]=find(max(A(:))==A)
i =
    52
j =
    9601
k =
     1
Run Code Online (Sandbox Code Playgroud)

但使用这些索引会得到以下结果:

>> A(i ,j, k)
??? Index exceeds matrix dimensions.
Run Code Online (Sandbox Code Playgroud)

如何解决问题?

matlab

2
推荐指数
1
解决办法
48
查看次数

标签 统计

matlab ×3

image-processing ×1

overloading ×1

rotation ×1