Accessing variables from a .m file
I run a program, which is a function - here I'll call it 'myfxn' - that output开发者_运维问答s several different variables. But when I try to access the data I get
??? Undefined function or variable 'myfxn'.
How do I access the data? Thanks for your help.
Your question is a bit confusing - you claim you run the function, but then you also say that Matlab throws an error indicating it can't run the function.
Here's two things to test
- Is
myfxn
on the Matlab path? Run the commandwhich myfxn
. If that does not find the function, change directory (usingcd
or the directory browser on the Matlab Desktop) to wheremyfxn
is located. - Does the function actually generate output? If it's a function, the first line should look something like this:
function [out1,out2] = myfxn(in1,in2)
, wherein1
andin2
are two input arguments, andout1
andout2
are output arguments. Then, you could callmyfxn
like this:[a,b] = myfxn(2,'something');
, and it will use the two inputs to generate the two outputs, which are assigned toa
, andb
, respectively.
精彩评论