MATLAB: Grouping rows and store is separate matrix

filtering and grouping rows

hi all,
in the script below I have p which is (m,3) vectors matrix, Itried to group this matrix according to z-value in L1 vector, so in case L1 is (0,0-2), rows of matrix p should be filtered according to z=-2, and each filtered rows have to be seperatly stored. I failed to do this pls help
clc
clear
close all
format long
x=[];
y=[];
z=[];
for L=-2:0.5:2
for r=0:.5:2
for theta=0:45:360;
x=[x;r*cos(theta*pi/180)];
y=[y;r*sin(theta*pi/180)];
z=[z,L];
L1=[x-x,x-x,z'];
end
end
end
lx=L1(:,1);ly=L1(:,2);lz=L1(:,3);
z=z';
p=[x,y,z];
a = cell(length(L1),1);
for ii = 1:length(L1);
a{ii} = p(p(:,3) == L1(ii,3),:);
end
celldisp(a)

Best Answer

Hello Oday,
I couldn't understand you question completely but to to certain degree i could.
x=[x;r*cos(theta*pi/180)];
y=[y;r*sin(theta*pi/180)];
z=[z,L];
Do not think this is necessary. if i were u would do it this way.
x=[];
y=[];
z=[];
L = -2:0.5:2;
r=(0:.5:2)';
theta=0:45:360;
x = (r.*cos(theta*pi/180));
L1=[x-x,x-x,z'];
Again this part are you trying subtract elements in the 2nd column of matrix x from the 1st Column?
A little more detail might help.