creating matrix out of certain data of a matrix

1 view (last 30 days)
Hi guys. M = 1511x1 % this is a matrix with different values.
I want to take the data which are greater than 2 from M and put them in another matrix T.
So far I have this code, but it doesn't work :(
x=1;
T=[x:1];
while x<1512
if size(M(x,1))>2
k = M(x,1);
T(x,:) = k;
end;
x=x+1;
end;
Plz help.

Accepted Answer

Star Strider
Star Strider on 15 Apr 2014
I suggest:
% Create Data:
M = rand(1151,1)*10;
% Create Output Vector ‘T’
T = M(M > 2);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!