Use variables from workspace from previous run

18 ビュー (過去 30 日間)
Gerrit
Gerrit 2020 年 1 月 29 日
回答済み: Walter Roberson 2020 年 1 月 30 日
Hello guys,
is the following method possible to implement in Matlab:
If I run my function, it will load some mat files into the workspace. They are quite big and need over a secound for loading. As for this program, every second is really important, I am asking myself, if it is possible to load the mat files only at the first run after opening Matlab and after that just use them from the workspace?
I tried to not use clear and to check if the variable already exists with the exist function. Unfortunatly, this method doesn't work.
Do you have any suggestions?
Thank you very much in advance.

採用された回答

Walter Roberson
Walter Roberson 2020 年 1 月 30 日
Use
persistent VariableName
The value will be initialized to [] so isempty() tells you whether you need to load the value

その他の回答 (1 件)

Dimitris Kalogiros
Dimitris Kalogiros 2020 年 1 月 29 日
編集済み: Dimitris Kalogiros 2020 年 1 月 29 日
There are two possible scenarios:
  • your matlab code overwrites some of the preloaded values
  • you "load" the files inside the function call, so everything disappears when the function finishes its job
Provided that you don't use any "clear" command, you can use an m-file in order to load these useful files and store data containing to them at a variable (or variables) with a specific name. Then at the same m-file you can call your function and pass the data as prameters (maybe you have to change the definition of your function).
...at the end of the day, just run this m-script
  3 件のコメント
Dimitris Kalogiros
Dimitris Kalogiros 2020 年 1 月 30 日
編集済み: Dimitris Kalogiros 2020 年 1 月 30 日
So, the solution I've already proposed, has to fit to your problem.
This is what I meant at my answer
clear;
clc;
% call C++ function
myData=getMyData;
N=100;
for k=1:N
% keep your data protected
myDataCopy=myData;
%matlab function that processes my data
matlabFunctionThatProcessesMyData(Parameter1, Parameter2, myDataCopy);
end
Gerrit
Gerrit 2020 年 1 月 30 日
Thank you, but I need to call the Matlab function from C++. Not a C++ Function in Matlab.

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

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by