Unable to save individual cells of 2D cell array with save() function

5 vues (au cours des 30 derniers jours)
nassos
nassos le 6 Oct 2022
Commenté : nassos le 12 Oct 2022
Hi,
I have a 2D cell array that consits of 1x5 cells and each one of them is a separate 1x122 cell array.
When I am trying to save each of the 5 cells in a different file with save() function, I get the following error:
Error using save
'trace_set{1}' is not a valid variable name.
My code looks like this:
save(fname3,'trace_set{1}','-v7.3');
save(fname4,'trace_set{2}','-v7.3');
save(fname5,'trace_set{3}','-v7.3');
save(fname6,'trace_set{4}','-v7.3');
save(fname7,'trace_set{5}','-v7.3');
Is there an option to save individual cells of a 2D cell array, beside saving the complete cell array as is?
Thanks,
Nassos

Réponse acceptée

Sailesh Kalyanapu
Sailesh Kalyanapu le 10 Oct 2022
As per my understanding, you are looking to save individual cell elements using save() function.
save()’ function can be used to save individual cell elements as well as the entire cell.
But when using ‘save()’ function, names of the variables to be saved, are to be specified as character vectors or string scalars.
Thus to save individual elements of cell array, you would have to assign the individual element to a new scalar variable name
Example code:
Temp_variable = trace_set{1};
save(fname3,'Temp_variable','-v7.3');
For more information related to 'save()' function, refer to the documentation:

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by