Borrar filtros
Borrar filtros

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

21 visualizaciones (últimos 30 días)
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 ! :)

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 24 de Ag. de 2021
Editada: Cris LaPierre el 24 de Ag. de 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 comentarios
dsq dq
dsq dq el 24 de Ag. de 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 el 24 de Ag. de 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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by