フィルターのクリア

Reading the data from another m file in a loop

2 ビュー (過去 30 日間)
Bartosz Bagrowski
Bartosz Bagrowski 2022 年 5 月 6 日
コメント済み: Bartosz Bagrowski 2022 年 5 月 9 日
Hi guys, I created two functions, in the second one I'd like to read the data from the first one like this but in a smarter way, is it possible to use a loop somehow here? I'd like to read from t1 till t4 and from y1 till y50 and it's not convinient to write every single variable.
t1=model.t1;
t2=model.t2;
t3=model.t3;
t4=model.t4;
y1=model.y1;
y2=model.y2;
y3=model.y3;
y4=model.y4;
y5=model.y5;
y6=model.y6;
y7=model.y7;
y8=model.y8;
y9=model.y9;
y10=model.y10;
  1 件のコメント
dpb
dpb 2022 年 5 月 6 日
Use arrays and/or named fields instead -- don't create a sequence of variable names like this to begin with.

サインインしてコメントする。

採用された回答

Harsha Kalavakolu
Harsha Kalavakolu 2022 年 5 月 9 日
As per my understanding you want to send/access data from one function file to another function file.
You can go through the documentation below to see different ways of achieving that.
However, as you want to access many different variables try to put all those variables into a cell array and pass that as function arguments.
You can send this cell array to any function as argument and can access that from that function.
e.g.:
>>my_variables={t1, t2,t3, t4.......}
t1, t2 are variables in func1 and you want to access these in func2
then create cell array in func1 with t1, t2 as members and send cell array as argument to func2 from func1.
Here is an alternate solution:
If you do not want both functions to work simultaneously then you can save all the variables from workspace into a “.m“ file using save command and can load all these variables into workspace using load command.
Hope it helps!
  1 件のコメント
Bartosz Bagrowski
Bartosz Bagrowski 2022 年 5 月 9 日
Thank you very much, it helped me a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by