help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: n vectors of m rows from a m*n matrix


From: James Sherman Jr.
Subject: Re: n vectors of m rows from a m*n matrix
Date: Sun, 10 Feb 2013 13:17:56 -0500

On Sun, Feb 10, 2013 at 12:18 PM, robyandfra <address@hidden> wrote:
> Hi
> i have a matrix of m*n dimension (m and n are variable and depend on the
> previous part of the program).
> I need to work on each column of the matrix.
> how can a said to octave that it had to create:
> vector1
> vector2
> vector3
> .
> .
> .
> vectorn
> and keep them in the memory? Remember than n is variable...
> I have to add members on each vector so i need them saparated..
>
> i try in this way: example
>
> t=1:1:8 - time:length(t)=n
>
> A=[1,2,3,4,5,6,7,8;2,3,4,5,6,7,8,9]
>
> for e=1:length(t)
>         b=A(:,e)
> end
>
> but i get only one vector that is the last column of the matrix A.
>
>
> SOS
> bye
>
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/n-vectors-of-m-rows-from-a-m-n-matrix-tp4649721.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

Just to clarify, you want to have a variable number of vectors, and
that each vector has a different number of elements in it?

If so, what I think you want to use is a cell array.  Cell arrays work
similar to matrices but they allow different variable types in each
element.  For example:

A = cell(3,1) % create a 3 by 1 cell array
A(1,1) = [1 2 3]; % assign the vector [1 2 3] to element 1,1
A(2,1) = [4 5];
A(3,1) = 'foo';

And if you wanted to access the first element (this is where things
get kinda weird), you have to use curly brackets instead of the usual
parenthesis:

> A{1,1}
ans =

   1   2   3

Hope this helps,

James Sherman


reply via email to

[Prev in Thread] Current Thread [Next in Thread]