Calling .mat file into function

32 ビュー (過去 30 日間)
fatema saba
fatema saba 2014 年 12 月 8 日
回答済み: Pablo Díez 2020 年 3 月 21 日
Hi I have a question about calling contents of a .mat file into function. for example you save some matrices into .mat file and now you want to calling them into function.
How can do it please?

回答 (2 件)

Geoff Hayes
Geoff Hayes 2014 年 12 月 9 日
編集済み: Geoff Hayes 2014 年 12 月 9 日
Fatema - see the load function for details on loading a mat file.
  2 件のコメント
fatema saba
fatema saba 2014 年 12 月 9 日
Thank you, I have done that I have loaded('test.mat')like that:
function base=MyBase()
load('test.mat')
evalin('base','variable')
%my code
but for handling this function it is needed to load my .mat file from command window before. I want that I can handle or run my function without loading mat file from command window before that. thank you
Geoff Hayes
Geoff Hayes 2014 年 12 月 9 日
Fatema - I don't understand what you mean by it is needed to load my .mat file from command window before. Why not assign, in your function, the result of the load to a structure as
data = load('test.mat');
And, what is the purpose of the evalin call?

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


Pablo Díez
Pablo Díez 2020 年 3 月 21 日
You can extract the variable which you want from the model workspace doing the following in a Matlab Function block:
coder.extrinsic('get_param','getVariable');
mdlWks = get_param('your_model.slx','ModelWorkspace');
variable= getVariable(mdlWks,'variable_name');

カテゴリ

Help Center および File ExchangeManage Design Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by