How to load data without reloading?

10 ビュー (過去 30 日間)
Mr M.
Mr M. 2015 年 10 月 27 日
コメント済み: Chad Greene 2015 年 10 月 27 日
I would like to load variables from a .mat file, but just those ones which are not loaded before. It is possible not overwrite the variables?
  1 件のコメント
per isakson
per isakson 2015 年 10 月 27 日
編集済み: per isakson 2015 年 10 月 27 日

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

回答 (1 件)

Chad Greene
Chad Greene 2015 年 10 月 27 日
As I understand it, you have some variables in your workspace, let's call them x and y. You want to load some test.mat file that has variables x and y in them. You can do
x = 1;
y = 2;
t = load('test.mat');
x2 = t.x;
y2 = t.y;
  3 件のコメント
Chad Greene
Chad Greene 2015 年 10 月 27 日
You can try
m = matfile('test.mat');
w = who(m);
to the get names of the variables in test.mat.
Chad Greene
Chad Greene 2015 年 10 月 27 日
Or, putting it all together, if test.mat contains a variable named x, load it:
if any(strcmpi(who(matfile('test.mat')),'x'))
x = load('test.mat','x');
end
Similarly, you could compare the variables in test.mat to the variables in your workspace using ismember with who.

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

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by