MATLAB Answers

C Zeng

Define an array with variable

Asked by C Zeng
on 29 Apr 2013

Hello, I wonder how can I define an array with a variable, for example,

x_i=an array, where i changes. I do not think Matlab allows such operations. How can I accommodate it? Later on I will use x_i in loops.

Thanks.

  0 Comments

Products

No products are associated with this question.

2 Answers

Answer by Sean de Wolski
on 29 Apr 2013
 Accepted answer

FAQ

  5 Comments

C Zeng
on 29 Apr 2013

Thanks, Sean. Are you working at Mathworks? I use Matlab heavily on computing and I wish I can have opportunity to improve the speed of MATLAB.

C Zeng
on 30 Apr 2013

Oh, great! Thanks so much!


Answer by Azzi Abdelmalek
on 29 Apr 2013
k=4 
assignin('base',sprintf('x_%d',k),[1 2 3])

  1 Comment

C Zeng
on 29 Apr 2013

Thanks.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today