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

조회 수: 4 (최근 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).
tash7827
tash7827 2015년 8월 4일
편집: tash7827 2015년 8월 4일
thank you so much!! i have the correct file now :) and it works

댓글을 달려면 로그인하십시오.

추가 답변 (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