when i am saving workspce of function , it's not containing all variables.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Rik
2020 年 11 月 13 日
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?
採用された回答
Sudhakar Shinde
2020 年 11 月 13 日
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.
- Save base workspace to File1.m file
- 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 件のコメント
Walter Roberson
2020 年 11 月 13 日
save base workspace to mat file. save function workspace to same mat file with -append . Later load mat file.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File 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!