Function call problem. How to solve it?

I have a function, sliceobject(im). I used another m file to compute the input im. After that I used sliceobject(im) But the output can't show in workspace.
I directly use sliceobject with im input is okay.
how to show the output from sliceobject(im)

댓글 수: 2

Please give us the header of the sliceobject function (first line) and the line which executes this function. Maybe, even the entire code of the sliceobject function will be necessary to help you find the error.
function [ ] = SliceObject( im )
number=0;
abc=[];
abcd=[];
N=500;
k=1;
q=1;
l=q+1;
t=1;
constant=1;
control=[];
testvalue=[0];
Structure(N).result=zeros(15);
Result(N).volume=zeros(3);
Cell=im;
[R C]=size(Cell);
temp1=[];
num=0;
result=[];
counter=1;
for i= 1:R
for j=1:C
Cell(j,i);
if (find(Cell(j,i))==1)
temp=[i j];
temp1=cat(2,temp1,temp); % store all the true pixel into array
num=num+1;
end
end
end
a=temp1(counter); % true pixel
b=temp1(counter+1);
while (counter<=(size(temp1,2)-2))
j=(a-1)*R+b;
result=cat(2,result,j);
c=temp1(counter+2);
d=temp1(counter+3);
x=((c-a)^2+(d-b)^2)^(1/2);
if (x <= (2)^(1/2))
else
temp00=[];
temp00=result;
Structure(k).result=temp00;
k=k+1;
result=[];
number=number+1;
end
counter=counter+2;
a=temp1(counter);
b=temp1(counter+1);
end
while (l<=number)
tempcon=(abs(bsxfun(@minus,Structure(q).result',Structure(l).result)));
ans=(tempcon==R|tempcon==R-1|tempcon==R+1);
Tr=find(ans==1);
if (Tr>=1)
Structure(q).result=struct('object',[Structure(q).result Structure(l).result]);
Structure(q).result=Structure(q).result.object;
control=[control,q,l];
a=control;
end
if (l==number)
Result(t).volume=Structure(q).result;
aaa=q;
q=(1:number);
q=setdiff(q,control);
aa=q;
l=q(2);
q=q(1);
if (q==aaa)
control=[control,q];
q=(1:number);
q=setdiff(q,control);
l=q(2);
q=q(1);
end
t=t+1;
else
if (l==2)
l=l+1;
else
y= (isempty(Tr));
if (y==1)
l=l+1;
end
end
while any(l==a) && (l<number)
l=l+1;
end
end
end

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

답변 (1개)

Adam
Adam 2014년 8월 19일

0 개 추천

result = sliceobject(im);
should work fine.
Occasionally I find that my workspace doesn't refresh itself so I press F5 or just type e.g. 'result' on the command line to force the update and double check 'result' is in fact in the workspace.

댓글 수: 6

tabw
tabw 2014년 8월 19일
It won't work. I have many many output from that function
Adam
Adam 2014년 8월 19일
편집: Adam 2014년 8월 19일
Judging by what you just pasted in above you have no outputs from your function. Your function signature is:
function [ ] = SliceObject( im )
That means you have 0 output arguments (the same as if you just defined it as 'function SliceObject( im )'
If you want to return things from your function's workspace (which goes out of scope after the last line of the function you need, for example:
function [Structure, Result] = SliceObject( im );
then call this as:
[Structure, Result] = SliceObject( im )
on command line or in another function or script and then you can see those variables in your workspace.
tabw
tabw 2014년 8월 19일
편집: tabw 2014년 8월 19일
is there any ways to output all the stuff? without mention inside[]
Any way to output all the stuff?
Can I just write function=SliceObject(im)?
And I tried [Structure, Result] = SliceObject( im ). Not working. Still hided the output.
Actually, I just need Result(t).volume as output. I tried function [Result]=SliceObject(im) then [Result]=SliceObject(im).
however can't work
Adam
Adam 2014년 8월 19일
You need to be more specific than just "can't work".
The only way you get outputs from a function is to include them in the output argument list. If you want to output 20 arguments or whatever then you need to start questioning the design of your code as the purpose of a function is to hide a lot of the intermediate stuff in its own workspace and just return you the results you need.
I don't have time to understand your whole code so I just picked out 'Structure' and 'Result' as example variables in your function's workspace by a quick scan of the code. Despite that I still don't see why what I suggested would not return those two values assuming they are still in scope when your function ends which they seem to be.
If all you need as output is Result(t).volume it probably shouldn't be in a struct, but returning the entire Result array of structs should work as I said above (based on a glance over your code rather than an in-depth look) so you need to be more explicit what aspect of it doesn't work.
tabw
tabw 2014년 8월 19일
Actually,I need entire "Result" array of Structure. t=1......until it ends,let's say ,600.
I simply used function [Result]=SliceObject(im) and then [Result]=SliceObject(im).
It should work normally. But, I don't know why It won't work this time
But,nothing popped up and store in workspace
Adam
Adam 2014년 8월 19일
What did happen though? Did the function run to completion? Did you step in with the debugger and check everything was working as expected?

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

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

태그

질문:

2014년 8월 19일

댓글:

2014년 8월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by