MATLAB Answers

0

Creating a for loop that adds a number to a letter

Hi,
I'm trying to create a for loop that adds a number to a letter every time it loops. Here is my current code:
for count=1:99;
CM1=count;
CM2=count+1;
CM1X=['X',CM1]
CM2X=['X',CM2]
end
The problem that I am having is the X prints out fine, but the numbers print out as letters and then numbers and then characters. Here is what I am getting:
CM1X=
X
CM2X=
X .
.
.
CM1X=
X"
CM2X=
X/
and so on
Please help I'm not to sure what is going on.

  댓글 수: 0

로그인 to comment.

답변 수: 3

Answer by Azzi Abdelmalek
on 8 Mar 2013
Edited by Azzi Abdelmalek
on 8 Mar 2013
 Accepted Answer

for k=1:99
s{k}=sprintf('X%d',k)
end

  댓글 수: 0

로그인 to comment.


Answer by bym
on 8 Mar 2013

for insight into what is going on try
char(1:99)
does it look familiar to what you are getting?

  댓글 수: 1

로그인 to comment.


Answer by Brandon
on 8 Mar 2013
Edited by Brandon
on 8 Mar 2013

Here is the fixed code:
for count=1:99;
CM1=count;
CM2=count+1;
CM1X=sprintf('X%d',CM1)
CM2X=sprintf('X%d',CM2)
end
Thank you for your help!!

  댓글 수: 0

로그인 to comment.



Translated by