help-octave
[Top][All Lists]
Advanced

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

RE: Constructing arrays


From: dirac
Subject: RE: Constructing arrays
Date: Mon, 26 Jul 2010 06:33:59 -0700 (PDT)

Yes you did understand right! I understand how you do it now, and I do need to get rid of the zeros at the end. I was wondering how you would propose I do this? Would a for loop with an if statement be ok, or would that be slow to perform?
 
I do really appreciate your help Martin, Thanks again
 
Martin. A

From: Martin Helm [via Octave] [ml-node+[hidden email]]
Sent: 26 July 2010 14:23
To: Arnold M Mr (UG - Physics)
Subject: Re: Constructing arrays

Am Montag, 26. Juli 2010 14:56:48 schrieb dirac:

> Hi thanks for the reply,
>
> I see how this can work, but I am having problems with my data. The problem
> I think is that I have a matrix which I pre-defined as zeros, then replaced
> by numbers from a for loop calculation. I don't know how many rows I will
>  be using in the calculation (in the for loop) so I pre allocated more than
>  enough...Could this be a problem? Should I remove the zeros on the end of
>  the vector with the indecies in?
>
> Also could I have something like:
>
> a=[1:10]
> b=matrix
> col=some pre defined column from the matrix
> plot(a(1:length(b),col))
>
> it is b that has the zeros and indecies in.
>
> Sorry if this isn't very clear!
>
> Thanks
> Martin
>
> -----
> Pretty much convinced Octave>Excel for scientific data analysis!
>
If I understand this correctly and you want to use a column of the matrix for
the index it should read like this

plot(a(b(:, col)))

b(:, col) extracts the column number col from the matrix (so the result is a
vector of indexes).

Remark: I would remove the trailing zeros or if you don't want that and have
for example the value

m = number of nonzero values in the column

you can also do

plot(a(b(1:m, col)))

otherwise you will have an error like this (if index 0 is accessed)

error: subscript indices must be either positive integers or logicals.


- mh

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



View message @ http://octave.1599824.n4.nabble.com/Constructing-arrays-tp2302200p2302337.html
To unsubscribe from Re: Constructing arrays, click here.

Pretty much convinced Octave>Excel for scientific data analysis!


View this message in context: RE: Constructing arrays
Sent from the Octave - General mailing list archive at Nabble.com.

reply via email to

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