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

17 次查看(过去 30 天)
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 ! :)

采纳的回答

Cris LaPierre
Cris LaPierre 2021-8-24
编辑:Cris LaPierre 2021-8-24
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 个评论
dsq dq
dsq dq 2021-8-24
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 2021-8-24
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).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by