From: Paul doherty on
I'm pretty new to MATLAB coding. I have a matrix with multiple rows (the number varies) and 3 columns. That looks something like the following:
1 2 5
1.3 4 1
1.4 2 2
1.5 3 3

I'm sure this is really simple, but how do I reduce the matrix down. Specifically the first column contains increasing numbers. Depending on the application, I will want the matrix to contain numbers that will be below a specific number X (eg. 1.4). So I want to reduce the matrix down to:

1 2 5
1.3 4 1

However the number X changes for different applications and the matrix is massive. Any help greatly appreciated?
From: Frédéric Bergeron on
Hey,

I think this line may helps you.
X=1.4;
B=A(A(:,1)<X,:);

Fred
From: Andy on
"Paul doherty" <dohertyp(a)gmail.com> wrote in message <i1f65c$apr$1(a)fred.mathworks.com>...
> I'm pretty new to MATLAB coding. I have a matrix with multiple rows (the number varies) and 3 columns. That looks something like the following:
> 1 2 5
> 1.3 4 1
> 1.4 2 2
> 1.5 3 3
>
> I'm sure this is really simple, but how do I reduce the matrix down. Specifically the first column contains increasing numbers. Depending on the application, I will want the matrix to contain numbers that will be below a specific number X (eg. 1.4). So I want to reduce the matrix down to:
>
> 1 2 5
> 1.3 4 1
>
> However the number X changes for different applications and the matrix is massive. Any help greatly appreciated?

A; % your n x 3 matrix
x = 1.4; % your desired cutoff number
idx = A(:,1) < x; % get the row indices where the first column is less than x
B = A(idx,:); % return only those rows where the first column is less than x
From: us on
"Paul doherty" <dohertyp(a)gmail.com> wrote in message <i1f65c$apr$1(a)fred.mathworks.com>...
> I'm pretty new to MATLAB coding. I have a matrix with multiple rows (the number varies) and 3 columns. That looks something like the following:
> 1 2 5
> 1.3 4 1
> 1.4 2 2
> 1.5 3 3
>
> I'm sure this is really simple, but how do I reduce the matrix down. Specifically the first column contains increasing numbers. Depending on the application, I will want the matrix to contain numbers that will be below a specific number X (eg. 1.4). So I want to reduce the matrix down to:
>
> 1 2 5
> 1.3 4 1
>
> However the number X changes for different applications and the matrix is massive. Any help greatly appreciated?

one of the many solutions

m=[
1 2 5
1.3 4 1
1.4 2 2
1.5 3 3
];
r=m(m(:,1)<1.5,:)

us
From: someone on
"Paul doherty" <dohertyp(a)gmail.com> wrote in message <i1f65c$apr$1(a)fred.mathworks.com>...
> I'm pretty new to MATLAB coding. I have a matrix with multiple rows (the number varies) and 3 columns. That looks something like the following:
> 1 2 5
> 1.3 4 1
> 1.4 2 2
> 1.5 3 3
>
> I'm sure this is really simple, but how do I reduce the matrix down. Specifically the first column contains increasing numbers. Depending on the application, I will want the matrix to contain numbers that will be below a specific number X (eg. 1.4). So I want to reduce the matrix down to:
>
> 1 2 5
> 1.3 4 1
>
> However the number X changes for different applications and the matrix is massive. Any help greatly appreciated?

% One solution:

x = [1 2 5;1.3 4 1;1.4 2 2;1.5 3 3];
X = 1.35;
y = x(x(:,1)<X,:)
y =

1.0000 2.0000 5.0000
1.3000 4.0000 1.0000