how to create a input file?
显示 更早的评论
I have two function file (A & B). I would like to put all the variables that I found in function A file into an input file. That means all the variables from A function file is saved in that input file. So that B function can recall the variables from the input file. Does anyone know how to create the input file?? Million thanks.
采纳的回答
You can use save() to create a .mat file that you later load() from.
9 个评论
Hi Walter Roberson thanks for your reply. may I know need to save the name of function A of save every variables that existed in function A file?
Sorry, I am not sure what you are asking there.
If you want to save all variables in the workspace of a function, then you can do that with
save('TheMatFileNameHere.mat');
When you want to restore the variables it is best if you use something like
AVariables = load('TheMatFileNameHere.mat');
then
fieldnames(AVariables)
will tell you the names of all of the variables that were restored from the file, and you can recall them using structure notation. For example,
AVariables.x_median
would return the value that x_median had in the function at the time of the save().
You can also use, for example,
fn = fieldnames(AVariables);
for K = 1 : length(fn)
thisfield = fn{K};
fprintf('Variable %s had datatype %s\n', thisfield, class(Avariables.(thisfield)) );
end
Jing Lin Ng
2014-4-22
编辑:Walter Roberson
2014-4-22
sorry for do not asking my question clearly.
my first function file is as below:-
function wind=P1(object)
N=length(object);
wind = zeros(1,N);
wind(1) = object(1);
A=2*rand+object
B=3*rand+object*
then my second function file is as below:-
function speed=P2(weight)
GeneratedYears=30;
Y=GeneratedYears;
A=A';
B=B';
speed=A+weight
That means I want to use the output of variables A and B from first function file on my second function file.
How I can call the variables from the first function file?
You do not do that. The way you have defined A and B, they are private to the P1 function.
because there is an error when i run the second function file.
it says Input argument "A" is undefined.
The code you show would not produce that error. It could produce an error about "object" or "weight" as undefined input arguments, but your P2 routine would produce
Undefined function or variable 'A'
not a message about input argument"A"
so what should I do to be able to use the variable A and B in my second function file?
Those techniques can be used even when you are not using callback functions.
alright thanks for you answer!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
