Sometimes I would rather not like to show my data to other people and therefore I need to modify it. When it is ready for export, I wish to export the workspace data, for instance a table, exactly as it is, for POSTING it here for instance.
I know the generate script function, and i feel the answer is somewhat related but it is not that, and publish is also not the command i require. How do i do that?
UPDATE with example:
How do i print a table as code?
%% Table example to export workspace T={'A2P3';'A2P3';'A2P3';'A2P3 with (extra1)';'A2P3 with (extra1) and (extra 2)';'A2P3 with (extra1)';'B2P3';'B2P3';'B2P3';'B2P3 with (extra 1)';'A2P3'}; a={1 1 0 1 1 0 1 1 0 1 1 } T(:,2)=num2cell(1); T(3,2)=num2cell(0); T(6,2)=num2cell(0); T(9,2)=num2cell(0); T=table(T(:,1),T(:,2)); class(T.Var1); class(T.Var2); T.Var1=categorical(T.Var1) T.Var2=cell2mat(T.Var2) class(T.Var1); class(T.Var2);
Since Matlab 2014a there is this new feauture:
MATLAB now provides the ability to save workspace variables to a MATLAB script. Once the script is saved, you can regenerate the workspace variables by running the script. Click Save Workspace on the MATLAB desktop and select MATLAB script (*.m) in the Save as type menu. Alternately, use matlab.io.saveVariablesToScript to perform this operation from the command line.
Documentation fo matlab.io.saveVariablesToScript
If you don't have the new version, you will need to write your own I/O routine for your variables. It's quite easy to do that generic for numerical arrays, but it depends on the certain case.
If Matlab 14a is not available, I would use gencode from here
No comments:
Post a Comment