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)

 채택된 답변

Sai Gudlur
Sai Gudlur 2020년 6월 11일

0 개 추천

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.

댓글 수: 5

Oday Shahadh
Oday Shahadh 2020년 6월 11일
ok thanks to be patient with me
if I have two matrices A(5,3), B(20,3), A(x1,y1,z1),B(x2,y2,z2)
so for instance if A(1,2,3), I need to group out all rows from B that have the same z-value in A, which is (3)
Oday Shahadh
Oday Shahadh 2020년 6월 11일
L1 is just to creat vector of (0,0,z), have the same length of x &y
Oday Shahadh
Oday Shahadh 2020년 6월 11일
in the attched image you can see multi level set of points, I need to cross product between each center point of each level with its related points at the same level which the surley have the same z-value, so it need to group out each set of points then make the cross product
Sai Gudlur
Sai Gudlur 2020년 6월 11일
I do not know how much would this help but try.
"ismember" or if i were you would try "intersect". This would return the values that have the same A&B "z" value. and then you could proceed to do that operation.
Another possibility is you could use "Unique" and find the ones that aren't the same and later use the common values of A & B.
Oday Shahadh
Oday Shahadh 2020년 6월 11일
your first accepted answer :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2020년 6월 11일

댓글:

2020년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by