Thread: Matlab ..... help

1. Matlab ..... help

Hi guys
i have a problem with a Matlab code
i have a matrix noz=[2 1 5] %%%% noz = number of zero
and i want to reprsent each element in that matrix by the same number of zero (vertically)
for example the element 2 must show 2 zeros in a column like this
0
0
and the element 1 must show 1 zero in a column like this
0

and the element 5 must show 5 zero in a column like this
0
0
0
0
0

indeed i have this code
noz=[2 1 5]
for i=1:length(noz)
k=[zeros(1,noz(1,i))']
end

the result is

noz =
2 1 5

k =
0
0

k =
0

k =
0
0
0
0
0

right now everything is fine , but my problem is
how can i number each k
for example k(1) gives me
k(1)=
0
0

and
k(2) =
0

k(3) =
0
0
0
0
0

I tried to implement it , but it was wrong as shown
%%%number of zero=noz
noz=[2 1 5]
for i=1:length(noz)

k(i)=[zeros(1,noz(1,i))']
end

i need your help guys ..... thank you

2. A matrix must have a fixed number of entries in each row/column. But a cell array does not have this limitation, so you can write:

clc
noz=[2 1 5];
for i=1:length(noz)
k{i}=[zeros(1,noz(1,i))'];
k{i}
end

Search Tags

matlab 