MatLab-使用run时出错=>;输入参数未定义

MatLab-使用run时出错=>;输入参数未定义,matlab,Matlab,作为一名MatLab新手,我在运行以下脚本时遇到问题: function [ newarray ] = reshapeIm( array, period ) %reshapeIm(array, period) Summary of this function goes here % Detailed explanation goes here le = length(array); fra = le/period; array = [array, zeros(1, ceil(fra)*p

作为一名MatLab新手,我在运行以下脚本时遇到问题:

function [ newarray ] = reshapeIm( array, period )
%reshapeIm(array, period) Summary of this function goes here
%   Detailed explanation goes here


le = length(array);
fra = le/period;
array = [array, zeros(1, ceil(fra)*period-le)];

newarray = reshape(array', period, []);

end


load('1200rpm_shak3.mat');

cRounds = 54;

mylength = 100;
thetas = (1:cRounds*mylength).*2*pi/mylength;
thetas0 = (1:mylength).*2*pi/mylength;

figure; 
plot(z1(1:300), '.-');
plot(z2(1:300), '.-');

z1s = z1;
z2s = [z2(mylength/4+1:end) z2(1:mylength/4)];
z3s = [z3(mylength/2+1:end) z3(1:mylength/2)];
z4s = [z4(mylength*3/4+1:end) z4(1:mylength*3/4)];

dr = 1/4.*(z1s+z2s+z3s+z4s); % gemittelt
drs = reshapeIm(dr, mylength);
drs_std = std(drs, 1, 2);
drs_meanstd = mean(drs_std);


figure;
polar(thetas, 250000+200*dr);

figure;
polar(thetas0', 250000+200*mean(drs,2));
命令窗口显示:

??? Error using ==> run
Input argument 'array' is undefined.

我想,这是因为脚本是为更新的MatLab编写的,但我使用的是5.3。

函数需要在它们自己的文件中。不能在脚本文件中定义函数。因此,要让代码正常工作,需要将文件顶部的函数(我在下面复制了该函数)移动到它自己的文件中。将文件命名为“reformaeim.m”,并将其保存在您进行工作的同一目录中

function [ newarray ] = reshapeIm( array, period )
%reshapeIm(array, period) Summary of this function goes here
%   Detailed explanation goes here


le = length(array);
fra = le/period;
array = [array, zeros(1, ceil(fra)*period-le)];

newarray = reshape(array', period, []);

end 

然后,从脚本中删除函数后,保存脚本并再次运行。这应该可以解决功能方面的问题。您可能有其他错误,但这应该考虑您报告的错误。

哪一行产生错误?您是否使用输入调用该函数,即对于某些向量
m
和数字
n
?或者你只是在Matlab编辑器中点击run按钮?你对提问者的意思是什么?我认为这是侮辱性的。那根本不是有意侮辱你。我真的认为你所遇到的是我过去见过的一个常见问题,这是大卫内心的一个小笑话。重读你的问题并看到解决方案,我意识到它不是,所以如果我冒犯了你,我道歉。祝你好运!非常感谢。不知道函数必须有单独的文件。我今天要试一试。