Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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

Respuesta aceptada

James Tursa
James Tursa el 4 de Ag. de 2015
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 comentarios
James Tursa
James Tursa el 4 de Ag. de 2015
Editada: James Tursa el 4 de Ag. de 2015
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 el 4 de Ag. de 2015
Editada: tash7827 el 4 de Ag. de 2015
thank you so much!! i have the correct file now :) and it works

Iniciar sesión para comentar.

Más respuestas (1)

Kelly Kearney
Kelly Kearney el 4 de Ag. de 2015
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?

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by