Can somebody tell me why, when I call a function using an input, the input is disregarded?

1 次查看(过去 30 天)
I have a function,
function cubefinal = sensingmatrix3d(time)
and I call it like this if I want time=3:
cubefinal = sensingmatrix3d(3);
but it is not working (the body of the function is correct) because when I displayed 'time', answers seemed totally random:
>> test3dmatrix
time =
6
>> test3dmatrix
time =
6
>> test3dmatrix
time =
7
>> test3dmatrix
time =
7
>> test3dmatrix
time =
4
>> test3dmatrix
time =
5
could somebody please tell me why time is random? and how to fix it? thank you.
Edit: sorry -- here is my code
function cubefinal = sensingmatrix3d(time)
exposure=zeros(60,96,10);
if time==3
for j=1:size(exposure,1);
for jj=1:size(exposure,2);
randnum=randi([1 8]);
exposure(j,jj,randnum:randnum+2)=1;
%if rand < 0.003
% checkRow=reshape(exposure(j,jj,:), [1 10])
%end
end
end
elseif time == 4
for j=1:size(exposure,1);
for jj=1:size(exposure,2);
randnum=randi([1 7]);
exposure(j,jj,randnum:randnum+3)=1;
end
end
elseif time == 5
for j=1: size(exposure,1);
for jj=1:size(exposure,2);
randnum=randi([1 6]);
exposure(j,jj,randnum:randnum+4)=1;
end
end
elseif time == 6
for j=1:size(exposure,1);
for jj=1:size(exposure,2);
randnum=randi([1 5]);
exposure(j,jj,randnum:randnum+5)=1;
end
end
elseif time == 7
for j=1:size(exposure,1);
for jj=1:size(exposure,2);
randnum=randi([1 4]);
exposure(j,jj,randnum:randnum+6)=1;
end
end
end
cubefinal=exposure;
disp(time)
end

采纳的回答

James Tursa
James Tursa 2015-8-4
You show code for function sensingmatrix3d, but your example is calling test3dmatrix. How are the two related? Look at how test3dmatrix is calling your function.
  14 个评论
James Tursa
James Tursa 2015-8-4
编辑:James Tursa 2015-8-4
It means one of two things. Either you did not set the breakpoint in your test3dmatrix properly, or it means you are not calling the test3dmatrix file that you think you are calling. Check again what you get with the following:
which test3dmatrix
And then make sure you edit that exact file in the directory it shows. Then set a breakpoint in that exact file. Then make another run. It should pause at the line in test3dmatrix where you just set the breakpoint (i.e., the line where you call sensingmatrix3d).

请先登录,再进行评论。

更多回答(1 个)

Kelly Kearney
Kelly Kearney 2015-8-4
My crystal ball says you have a typo on line 23 of your function. Of course, my crystal ball is pretty unreliable...
Perhaps showing some code would help our divining?

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by