Azzera filtri
Azzera filtri

Error using save 'handles.final_cell' is not a valid variable name.

21 visualizzazioni (ultimi 30 giorni)
Hey everyone !
I might be be stupid, because some people got the same problem, but I didn't find the solution in their topics :(.
I'm trying at the end of my programm to save the data of a cell (let's call it final_cell) and this cell is contained into a structure (handles) so the total name of the cell is : handles.final_cell.
I wrote this line :
save('Final values.mat', 'handles.final_cell');
but this error appears : 'handles.final_cell' is not a valid variable name. I don't know how to fix it :/.
I hope it was quite understandable because my english is not perfect !
Thanks in advance ! :)

Risposta accettata

Cris LaPierre
Cris LaPierre il 24 Ago 2021
Modificato: Cris LaPierre il 24 Ago 2021
You could try this, but it will save every field in your structure to the mat file, not just final_cell.
save('Final values.mat','-struct','handles')
If you just want final_cell, try the following instead.
final_cell = handles.final_cell;
save('Final values.mat','final_cell')
  2 Commenti
dsq dq
dsq dq il 24 Ago 2021
Well thanks it works ! but why should I write this line ?
final_cell = handles.final_cell;
I don't get it
Cris LaPierre
Cris LaPierre il 24 Ago 2021
Because you need to pull the data out of the structure field and put it in its own variable to save just that data.
As you observed, save only accepts variable names. So either you save the entire structure, or you create a variable containing the data you want, and just save that variable.
There is a check that makes sure the variablenames passed as input to save are valid, and handles.final_cell is not a valid MATLAB variable name because it contains a period (hence the error message you were getting).

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by