help-octave
[Top][All Lists]
Advanced

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

Re: create a vector and vector of matrix


From: James Sherman Jr.
Subject: Re: create a vector and vector of matrix
Date: Wed, 13 May 2009 11:32:28 -0400

I'm not exactly sure what you're aiming for, but for example
> repmat(0, length(A), 1)
could also be written as
> zeros(length(A), 1)

or
> repmat(1, length(A1), 1)
could be written as
> ones(length(A1), 1)

Doesn't work for twos though. :(  So for twos you could do:
> 2*ones(length(A2), 1)
but that would be somewhat inefficient compared to repmat if you're doing lots of them.

To access a matrix using indices, there are two ways that I can think of.  First, you could use a cell array:
> C = cell(5,1);
> C{1} = A0;
> C{2} = A1;
and so on.  Then you access the A0 array by using C{1}  (note the curly brackets, they denote that C is a cell array vs. a normal array).

The other way is to make a 3 dimensional array.  This would only work if all the Ai matrices are of the same size.  Then you could do:
> C = zeros(size(A0, 1), size(A0, 2), 5);
> C(:, :, 1) = A0;
> C(:, :, 2) = A1;
Then you can access the A0 matrix by similarly using C(:, :, 1).  Note that depending on what you're doing with the matrix (if you're multiplying the matrices for example), you'll need to use the squeeze function on the matrix since its technically still a 3d matrix even though the last dimension is 1.

Hope this helps.

On Wed, May 13, 2009 at 10:46 AM, Carlo Rossi <address@hidden> wrote:
Hello,
 I need to create a vector; this work but is there something more compact?

repmat(0, length(A), 1)

eg:
0
0
0
0
furthermore as I have to repeat the operation for 5 times, there is the way to do it in a loop as well:
repmat(0, length(A0), 1)
repmat(1, length(A1), 1)
repmat(2, length(A2), 1)
repmat(3, length(A3), 1)

I mean: is it possible to create a vector of matrix indexes a vecot like this
V = [A0 A1 A2 A3] and use V[i] to access to a matrix?

thanks



_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

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