Function call problem. How to solve it?
Show older comments
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 Comments
Michael Haderlein
on 19 Aug 2014
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
on 19 Aug 2014
Answers (1)
Adam
on 19 Aug 2014
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 Comments
tabw
on 19 Aug 2014
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
on 19 Aug 2014
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
on 19 Aug 2014
Adam
on 19 Aug 2014
What did happen though? Did the function run to completion? Did you step in with the debugger and check everything was working as expected?
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!