when i am saving workspce of function , it's not containing all variables.

when i am saving workspce of function , it's not containing all variables. and when i run through command window it showing all data for the same data.
why it's showing the difference between workspace?

댓글 수: 3

There are some kinds of variables that are not serializable and cannot be completely saved to files. Device related variables often cannot be saved, and variables related to Parallel Computing Toolbox cannot always be saved.
Thanks for the reply.but i am using some variables in function and exporting workspace to .m file and other side using same execution through command window and exporting into another .m file . when i am comparing both the files , some data missing in .m file exported from function.
is any command available to merge the base and function workspace?
Your comment is very confusing. Data is not saved in an m file, but in a mat file.
Why would you want to merge the base and function workspace? If you want them to be the same you can use a script. The whole point of functions is to hide the internals from the caller. What do you want to achieve?

댓글을 달려면 로그인하십시오.

 채택된 답변

There may not be direct function available to merge two workspace data directly. If you would like to save base workspace and function workspace variables to '.m' files. I feel below can be a workaround to do it.
  1. Save base workspace to File1.m file
  2. Save function workspace to File2.m file
Then use function to merge two .m files:
function Merge2Mfiles(file1,file2)
run(file1);
run(file2);
Data = whos;
Data = Data(~contains({Data.name},{'file2','file1'}));
matlab.io.saveVariablesToScript('Out.m', {Data.name});
end

댓글 수: 1

save base workspace to mat file. save function workspace to same mat file with -append . Later load mat file.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2020년 11월 12일

댓글:

2020년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by