- Forcing meta-data (pseudo-indices) into variable names, thus making your code slow and complex.
- Forcing code into one line, when clarity is actually more important (as this question demonstrates).
- Two variable names must be supplied as two inputs to SAVE (not concatenated together as you are doing):
save two variables using num2str
17 views (last 30 days)
I want to save two variables using num2str, but I get error. what is wrong with this?
pathdatasave = (['D:\testa\ty' num2str(ty_c) '\']);
save([pathdatasave 'test_x' num2str(x1) '_y' num2str(y1) '.mat'],['varx' num2str(x1) ,'vary' num2str(y1)]);
Stephen23 on 11 Jul 2022
Edited: Stephen23 on 12 Jul 2022
"what is wrong with this?"
varx1 = 33;
vary2 = 444;
P = '.';
F = fullfile(P,sprintf('test_x%d_y%d.mat',x1,y1));
N1 = sprintf('varx%d',x1);
N2 = sprintf('vary%d',y1);
% ^^ ^^ two variable names == two inputs, not one like you did!
whos -file test_x1_y2.mat
So, everything works exactly as documented and expected.