MATLAB Answers


Question in creating variables.

Asked by Portgas Ace on 30 Sep 2012
How do i create variables in each iteration? like x_1 to x_n and then assigning values/arrays to each of them.


Show 1 older comment
Matt J
on 30 Sep 2012
I think you already asked this question (and got satisfactory answers) here:
not answered. :( because i have to show 'A1' , 'A2', 'A3' to 'An' in my output. which will be determined depending on the initialization.
output should look like this
(sorry for using -, spaces dont work)

Sign in to comment.


1 Answer

Matt J
Answer by Matt J
on 30 Sep 2012
 Accepted Answer

I would do something like this:
labels=arrayfun(@(i) ['A' num2str(i)], 1:3,'uni',0).';
data=cellfun(@(a) num2str(a), num2cell(A),'uni',0);
result=[labels, data]
result =
'A1' '3' '5' '6'
'A2' '5' '3' '4'
'A3' '6' '7' '9'

  1 Comment

thank you :D ive done something simple to understand but a bit longer.

Sign in to comment.