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

New to MATLAB?

Define an array with variable

Asked by C Zeng

C Zeng (view profile)

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

C Zeng

C Zeng (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Sean de Wolski

Sean de Wolski (view profile)

on 29 Apr 2013
Accepted answer

FAQ

5 Comments

C Zeng

C Zeng (view profile)

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

C Zeng (view profile)

on 30 Apr 2013

Oh, great! Thanks so much!

Sean de Wolski

Sean de Wolski (view profile)

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

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

1 Comment

C Zeng

C Zeng (view profile)

on 29 Apr 2013

Thanks.

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Contact us