Error using save 'handles.final_cell' is not a valid variable name.
17 views (last 30 days)
Show older comments
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 ! :)
0 Comments
Accepted Answer
Cris LaPierre
on 24 Aug 2021
Edited: Cris LaPierre
on 24 Aug 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 Comments
Cris LaPierre
on 24 Aug 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).
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!