MATLAB: When I try to get a prompt to show a variable in it, it shows a random symbol instead

input

For example, in my code [r,c] = size(Temp_Data) assigns r to be 366. However, when I try to prompt the user to enter a number between 1 and r using this code
input(['Please choose a day from 1 to ' c '\n'])
the r shows up as a Ů and if I use c in place of r I get instead. Anyone know why the number isn't showing?

Best Answer

pmt = sprintf(Please choose a day from 1 to %d\n',c);
day = str2double(input(pmt,'s'))
You assumed that by concatenating a numeric value c with some characters MATLAB would magically convert that number into a string representation of that number, whereas in fact MATLAB converts it into a character with that character code, e.g. if c was equal to 32 then you would get a space character. You can learn about character codes here:
If you want to get the string representation of a number then use one of the functions that convert to string, e.g. sprintf, num2str, etc.
Related Question