필터 지우기
필터 지우기

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

조회 수: 21 (최근 30일)
dsq dq
dsq dq 2021년 8월 24일
댓글: Cris LaPierre 2021년 8월 24일
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에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by