フィルターのクリア

Use save function with '-fromstruct' option to save a cell array

6 ビュー (過去 30 日間)
Roman
Roman 2024 年 5 月 14 日
コメント済み: Stephen23 2024 年 5 月 14 日
To save several variables in a ,mat file within a parfor loop, I'm using a '-fromstruct' option. In this case, an attempt to save cell array throws an error. If I replace a cell array with a string array - it works perfectly. However, I would like to avoid conversion from cell to string and back. Any ideas how to resolve this? Thank you
test_file = 'test.mat';
files={'test1.m', 'test2.m'};
T = ones(1,length(files));
save(test_file,'-v7.3', '-fromstruct', struct('T', T, 'files', files));
Error using save
The -FROMSTRUCT option must be followed by a scalar structure variable.

採用された回答

Stephen23
Stephen23 2024 年 5 月 14 日
編集済み: Stephen23 2024 年 5 月 14 日
As the error message states, the structure must be scalar:
test_file = 'test.mat';
files = {'test1.m', 'test2.m'};
T = ones(1,length(files));
save(test_file,'-v7.3', '-fromstruct', struct('T',T,'files',{files}))
% ^ ^
The documentation explains how to define a scalar structure with cell arrays:
  2 件のコメント
Roman
Roman 2024 年 5 月 14 日
It works! Thank you!
Stephen23
Stephen23 2024 年 5 月 14 日
@Roman: please remember to click the accept button if my answer helped you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by