Results 1 to 2 of 2

Math Help - Matlab ..... help

  1. #1
    Newbie
    Joined
    Oct 2008
    Posts
    13

    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
    Attached Thumbnails Attached Thumbnails Matlab ..... help-m1.jpg   Matlab ..... help-m2.jpg  
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    May 2008
    From
    Melbourne Australia
    Posts
    210
    Thanks
    24
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 02:59 AM
  2. Matlab FFT Help
    Posted in the Math Software Forum
    Replies: 0
    Last Post: June 3rd 2009, 12:48 PM
  3. help about ODE in matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 31st 2009, 03:10 AM
  4. Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 6th 2008, 08:46 AM
  5. Matlab
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 20th 2008, 10:39 PM

Search Tags


/mathhelpforum @mathhelpforum