Saving a 1x2 structure with 5 fields

I am trying to save my structure that I've called "mymat" in the workplace area as a file. When I try to save it like:
>> save ('mysummat.mat', '-struct', 'mymat');
I get the error message:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
When I try to save it like:
>> save ('mysummat.mat', 'mymat')
I get the error message:
Error using save
Unable to write file mysummat.mat: No such file or directory.
I just want to be able to save this structure array specifically.

1 件のコメント

Stephen23
Stephen23 2016 年 7 月 14 日
編集済み: Stephen23 2016 年 7 月 14 日
Never use the name of an inbuilt function to name your own function or variable
This means you should never use sum, length, mean, size, i, j, etc, etc.
This will only cause untold heartache and hard to diagnose problems. Use which to check names before you use them.

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

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 14 日

0 投票

First, avoid using sum as a variable because it's a built-in Matlab function
som.a=4
som.b=5
save ('mysum.mat', '-struct', 'som')

5 件のコメント

Jocelyne Beelen
Jocelyne Beelen 2016 年 7 月 14 日
I still get the error: Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 14 日
Post the code you tested
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 14 日
Ok, then try this
som=struct('a',{1 2},'b',{3 4})
save ('mysum.mat', 'som')
Jocelyne Beelen
Jocelyne Beelen 2016 年 7 月 15 日
I just want to save the entire structure that's called mymat in the workspace as a file. Is this possible?
Stephen23
Stephen23 2016 年 7 月 15 日
save('myFileName.mat','mymat')

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

カテゴリ

ヘルプ センター および File ExchangeScope Variables and Generate Names についてさらに検索

質問済み:

2016 年 7 月 14 日

コメント済み:

2016 年 7 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by