I'm following an online course to learn and practice matlab. In the course, the guys writes:
basefilename = 'testfile';
filename = [basefilename num2str(1) ".mat"]
and Matlab returns:
testfile1.mat
However, when enter the same input, I get the following as an output:
filename =
1×3 string array
"testfile" "1" ".mat"
I tried a more usual concatenating method by inputting
filename = [basefilename + "1" + ".mat"]
And go the correct output:
testfile1.mat
However, when changing the "1" to num2str(1) (in order to replace the number by a variable that can vary in a for loop later on):
filename = [basefilename + num2str(1) + ".mat"]
I get a completely different output:
filename =
1×8 string array
"165.mat" "150.mat" "164.mat" "165.mat" "151.mat" "154.mat" "157.mat" "150.mat"
I was wondering if someone could explain why each input methods returns such drastically different outputs. It seems to me like all three methods should return the same thing...
'test') and actual strings ("test") is a problem here? See Create String Arrays from the MATLAB documentation for further reading."as if it were'. You should translate all their double quotes to single quotes.