help-octave
[Top][All Lists]
Advanced

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

Re: how to know index of matrix


From: febty febriani
Subject: Re: how to know index of matrix
Date: Wed, 13 Feb 2013 16:23:47 +0900

James,

Yes, it is what I want to. Thanks very much for your help.

Best regards,
febty


On Wed, Feb 13, 2013 at 3:52 PM, James Sherman Jr. <address@hidden> wrote:
On Wed, Feb 13, 2013 at 1:17 AM, febty febriani <address@hidden> wrote:
> Hi everyone,
>
> For example A is a matrix which having 3 column and some rows. I want to
> pick up the second and the third column of the A matrix while the first
> column has value less than or equal to 10 and more than or equal to 1.
>
> How to define the index of the first column that having value is less than
> or equal to 10 and more than or equal to 1? According to this condition I
> want to pick up the first, the second and the third column.
>
> Below is my illustration :
>
> if (1 <= A(:,1) <= 10);
>  B=A((row which having value is less than or equal to 10 and more than or
> equal to 1 ), :);
> end;
>
> Any help is welcome. Thanks very much in advance.
>
> Best regards,
> Fety
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

You can't have to inequality statements in the same line (well you
can, but it won't do what you want it to).  What I think you want is
something like:
rows_morethan1 = A(:, 1)>=1;
rows_lessthan10 = A(:, 1)<=10;
desired_rows = (rows_morethan1) & (rows_lessthan10);
B = A(desired_rows, :);

Obviously you could compress this code some, but probably with the
loss of some readability.

Hope this helps.

James Sherman


reply via email to

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