Borrar filtros
Borrar filtros

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

6 visualizaciones (últimos 30 días)
Roman
Roman el 14 de Mayo de 2024
Comentada: Stephen23 el 14 de Mayo de 2024
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.

Respuesta aceptada

Stephen23
Stephen23 el 14 de Mayo de 2024
Editada: Stephen23 el 14 de Mayo de 2024
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 comentarios
Stephen23
Stephen23 el 14 de Mayo de 2024
@Roman: please remember to click the accept button if my answer helped you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by