How to load variable from function workspace to Base workspace ?

24 ビュー (過去 30 日間)
Shiv Nileshkumar Matliwala
Shiv Nileshkumar Matliwala 2022 年 12 月 15 日
Suppose I have a file called file123.m and inside this file I am calling one function load_func().
Now let's assume there is one variable call 'A' which is a bus object inside the function load_func(). so, Now i want to load the variable A into my base workspace of file file123.m
So, how can I do this ?
If anyone has any idea or the ways to do it, please help me.
Thank you so much.
  7 件のコメント
Stephen23
Stephen23 2022 年 12 月 19 日
編集済み: Stephen23 2022 年 12 月 19 日
"What if I have one bus object which is being made iteratively."
Then you use indexing, just like MATLAB is designed for.
"If my for loop is running for lets say 50 iterations, so 50 Bus Objects will be created and Its not appropriate to give 50 bus objects as an Output"
Why not? I store objects from loops all the time, most MATLAB users do. You can very simply use indexing to store objects in a cell array or probably an object array. How to use loops and indexing is the simple and efficient approach to this task. The basics of how to use loops and indexing is explained in the introductory tutorials:
Rather than your complex and inefficient approach, you should just use basic indexing. Indexing is a MATLAB superpower.
Shiv Nileshkumar Matliwala
Shiv Nileshkumar Matliwala 2022 年 12 月 23 日
My question here is that
suppose I have my Main.m script which has a function Fun1 and the function Fun1 has another function inside it which is Fun2
So, now I have one bus object created inside this Fun2 then I want to transfer that function into the Main.m's script Workspace which is my Base Workspace.
So, can you tell me how can i make this ?
So, in general way I want to find a way that I can store variables from any workspaces to my Base Workspace without using assign, assignin, eval and evalin functions.

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

回答 (1 件)

Marcel
Marcel 2022 年 12 月 19 日
編集済み: Marcel 2022 年 12 月 19 日
I used to save some information like in this example
function SaveJob(~, filename, importJob)
save("path\dir\" + filename, "importJob");
end
loaded it like so
load("path\dir\filename");
and accessed the data like that:
importJob(1,3)
I called it like that
vars = [RadiusMin, RadiusMax, Crop, Sensitivity, Method, Rotation, Active, FontSize, ImagePath, TargetRadius, TargetTolerance, TCP];
SaveJob(app, jobname + "\\" + tmp_taskname, vars);
it kinda depends on your setup but maybe this helps a little bit
  1 件のコメント
Shiv Nileshkumar Matliwala
Shiv Nileshkumar Matliwala 2022 年 12 月 19 日
Thank you but I need to look for my set up then.

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

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by