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.




No products are associated with this question.

2 Answers

Answer by Sean de Wolski
on 29 Apr 2013
 Accepted answer



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

assignin('base',sprintf('x_%d',k),[1 2 3])

  1 Comment

C Zeng
on 29 Apr 2013


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!