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
Michael Haderlein
2014년 8월 19일
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.
tabw
2014년 8월 19일
답변 (1개)
Adam
2014년 8월 19일
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
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.
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
2014년 8월 19일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!