2

I want to load multiple variables into one .mat file at the end of a process loop. I have a simple line of code :

save draw.mat Output

but I cannot work out a way to code 'use the name given by variable X' instead of 'Output', so that I can loop the process and save multiple variables in draw.mat

So then

X = 'Chocolate'

and the Variable name is saved as Chocolate.

I am sure it is simple but I cannot find a solution on here!

4

3 に答える 3

4

SAVEの機能形式が必要です。つまり、SAVEは次のように呼び出すことができます。

save('draw.mat', 'Output1', 'Output2');

したがって、保存する変数名が別の変数にある場合は、次のことができます。

v1 = 'Output1';
v2 = 'Output2';
save('draw.mat', v1, v2);

あるいは

v = {'Output1', 'Output2'};
save('draw.mat', v{:});

SAVEリファレンスページに詳細があります。

于 2012-06-27T10:56:59.983 に答える
2

-structコマンドの形式を使用できますsave。結果の .mat ファイル内の変数の名前を保持するフィールドを持つ構造体を構築します。

例:

s = struct();
s.VariableOne = 1;
s.VariableTwo = 2;
save draw.mat -struct s;

ファイル draw.mat は、"VariableOne" と "VariableTwo" という名前の 2 つの 1x1 double 変数を保持します。

1 つのコマンドで構造体を構築することもできます。

s = struct('VariableOne', {1}, 'VariableTwo', {2});

cell2structまたは、次の関数を使用できます。

data = {1,2};
names = {'VariableOne', 'VariableTwo'};
s = cell2struct(data(:), names(:), 1);
于 2012-06-27T11:01:06.727 に答える
0

させて

A = [2 5 8; 25 2 4; 4 1 7];
save('A.mat')

今、あなたはそれを別の名前で保存したいB

B = A;
save('B.mat')
于 2017-01-03T00:24:24.873 に答える