I have 21*1 Matrix. i have store it into z. then i have to slice these value as 1*1 Matrix and allocate (z1, z2, z3, z4.......z21) for 21 matrix. how can i allocate. please tell me command or allocation.

z =
1.0e-03 *
1.0000
0.9000
0.8000
0.7000
0.6000
0.5000
0.4000
0.3000
0.2000
0.1000
0
-0.1000
-0.2000
-0.3000
-0.4000
-0.5000
-0.6000
-0.7000
-0.8000
0.1000

2 Comments

Why do you need to allocate the values to 21 variables? You can access them with
z(i)
where i is between 1 and 21
@Ranjan Kumar Singh: Assigning to multiple variables is a bad way to program, and should be avoided. Read Julia's comment, and the answers to know why.

Sign in to comment.

More Answers (2)

Don't do this!
Please read:
Creating a list of variables dynamically and hiding an index in the name of the variable, is a really bad programming practice. Such complicated and indirect methods to create variables demand for even more complicated methods to use the variables later on. It will be nearly impossible to debug the code and the dynamic creation of variables slows down the processing substantially.
Follow Julia's comment and use z(i) instead.
I don't know why you need to create all these variables.
z=rand(1,21) % Example
for k=1:21
assignin('base',sprintf('z%d',k),z(k))
end

1 Comment

Please don't do this! Learn how to program properly in MATLAB, and it makes your own life easier. Read the other answers to know why.

Sign in to comment.

Tags

Asked:

on 8 Jul 2015

Edited:

on 19 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!