Store points into different cell arrays using if statement and ismember()

조회 수: 2 (최근 30일)
James Peach
James Peach 2020년 11월 11일
댓글: James Peach 2020년 11월 17일
I am working with cell arrays trying to store points in them. I am trying to use and if statement with ismember() as my trigger to store the remaining points left to be sorted in the next cell. If A (i,:) is a member of B, then the A(i,:) and all points in the matrix after A(i,:) should be stored in the same cell, until the next point that is a member of B occurs and triggers the switch into the next cell. I have 6 points in B and 6 different empty cells preallocated. Here is the code:
A = [0,0,0;0.00977495601952172,0.0129188554738323,0.999868768093125;-0.566794094824837,-0.823750570492204,0.0133959578031223;0.0279587435128966,0.0380588867245362,1.99938731654588;0.830388266617646,0.583999369869120,0.978401571089338;-1.07826433834531,-1.64452537544960,0.267810795303313;0.168715496407312,0.263085998125572,2.96351922435162;-0.791458202545459,0.611268411797120,0.998070417818667;-1.41124221175034,-0.289407593850698,0.0506110237693017;1.69942938355116,1.04462646221878,1.15892918358242;-1.55216375501531,-2.44987966243271,0.623934110066297;0.188310075544404,0.501770043093754,3.93441879647330;-1.44603145623221,1.35107113546187,1.15371676572365;-2.35391403973316,0.0183196401577155,0.179737992978120;2.59879677816763,1.38804628951095,1.42948622326796;-1.92629974765512,-3.28302931738291,1.03122259685150;0.190461468181228,0.731318108759712,4.90771374511875;-2.01837467713375,2.14014570650778,1.37684130228734;-3.30531517848174,0.217844651708771,0.414313445558867;3.50709118523837,1.65551615551852,1.75113998255253;-2.23204460424917,-4.13488361866807,1.45650407075820;0.193343935566412,0.934427321909631,5.88686559182864;-2.51244231909718,2.97180232130260,1.63030617210704;-4.25650570961388,0.357419056329789,0.689550723301627;4.41845060685608,1.87363023778730,2.10021053665969;-2.47842156351806,-4.99324597672323,1.90651791078471;0.204283419234320,1.13357858075284,6.86677329350173;0.617793464714887,0.0559247730198438,6.10612769252045;-2.96417360323821,3.81704174520463,1.91580426879081;-5.20242439373799,0.476408999682868,0.991344090368801;5.32672360772571,2.06445068867013,2.47253796167180;-2.69346338350278,-5.85030685131976,2.37470982965291;0.218591936197924,1.32878562119851,7.84743096960627;-3.26247612265381,-4.91985596911837,1.29018005288354;1.20197539596291,-0.580347098756520,6.61000225666269;-3.37592827171665,4.67443410026770,2.22457026832058;-6.14584567995603,0.584770610127789,1.30473528056482;6.23299868743130,2.22581272192086,2.86321400922248;-2.89467385558292,-6.70726873056154,2.84918921113506;0.209717491582492,1.53184472980862,8.82655723451965;5.28440710514136,1.17097130314088,2.91964410258613;0.576278852478300,2.24513662818586,7.66753960818188;-4.04653068178957,-4.84646596151352,0.673842194982372;1.72465217643194,-1.18852390077965,7.20743841278270;-3.76500316313530,5.53715317053961,2.54758193166533;-7.08499357301506,0.666849489054822,1.63829830698843;7.13773556686645,2.38268963160310,3.25924533904186;-3.08850223839479,-7.56458389242937,3.32609724340970;0.176682672356017,1.77636612069925,9.79563823738556;5.70892694024996,0.283366758099107,3.09836478191717];
x = A(:, 1);
y = A(:, 2);
z = A(:, 3);
SizeofA = size(A,1);
dist1a = nan(numel(x));
proximity = 1.000;
save_criteria = 3;
for i = 1:SizeofA
for j = 1:(i-1)
dist1a(i,j) = sqrt((x(i)-x(j)).^2 + (y(i)-y(j)).^2 + (z(i)-z(j)).^2);
dist1a(j,i) = dist1a(i,j);
end
end
i2keep = find(sum((dist1a - proximity <= eps('single')), 2) >= save_criteria);
keep_x1 = x(i2keep);
keep_y1 = y(i2keep);
keep_z1 = z(i2keep);
B = [keep_x1, keep_y1, keep_z1];
C = 1:SizeofA;
index = ismember(C,i2keep);
D = A(~index,:);
BranchGen = cell(1,size(B,1));
for i = 1:SizeofA
for j = 1:length(BranchGen)
if ismember(A(i,:),B)
BranchGen{1,j} = [BranchGen;A(i,:)];
else
BranchGen{1,j} = [BranchGen;A(i,:)];
end
end
end
  댓글 수: 6
Adam Danz
Adam Danz 2020년 11월 13일
If your data contain NaN values, use isequaln.
James Peach
James Peach 2020년 11월 17일
Okay thanks, I think I figured out my problem.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Preprocessing Data에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by