how to create a input file?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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.
採用された回答
Walter Roberson
2014 年 4 月 21 日
You can use save() to create a .mat file that you later load() from.
9 件のコメント
Jing Lin Ng
2014 年 4 月 21 日
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?
Walter Roberson
2014 年 4 月 21 日
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?
Walter Roberson
2014 年 4 月 22 日
You do not do that. The way you have defined A and B, they are private to the P1 function.
Jing Lin Ng
2014 年 4 月 22 日
because there is an error when i run the second function file.
it says Input argument "A" is undefined.
Walter Roberson
2014 年 4 月 22 日
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"
Jing Lin Ng
2014 年 4 月 22 日
so what should I do to be able to use the variable A and B in my second function file?
Walter Roberson
2014 年 4 月 22 日
Those techniques can be used even when you are not using callback functions.
Jing Lin Ng
2014 年 4 月 23 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
