MATLAB: Error in pop-up menu for GUI

guipopup menu

Hello everyone! I build a GUI for a main code that I have and based on the GUI, the user is supposed to enter a number, N. Once the number is entered, N is used to generate the list of a popup menu. example of list:
N = 3
User 1
User 2
User 3
my code and GUI functions properly, except when N is greater than 9. Then, instead of displaying User 10 in the pop up menu list, it is displaying User 1 User 0. This is occurring for all 2 digit numbers.
I tried a lot of options but none are actually working and I really need help! If anyone knows how to fix this, please help me!
This is the code I used:
for k = 2:(N+1)
string2{k} = sprintf('User %1.0g\n',(num2str((k-1),2)-48));
end
set(handles.popupmenu2,'String',string2)
Thank you

Best Answer

Hosheeta - part of the problem might be your conversion from a number to a string via num2str and the subtraction of 48 (ASCII conversion?). Since you are using sprintf, you do not have to do this. Consider the following code instead
N=11;
for k = 1:N
string2{k} = sprintf('User %d',k);
end
Try the above and see what happens!