MATLAB Answers

Filtering data separated by NaN rows for self-similarity

5 views (last 30 days)
Laura F
Laura F on 11 Jan 2020
Edited: KALYAN ACHARJYA on 11 Jan 2020
Hello,
I'm really not sure how to approach this task or even exctaly how to ask for help with it.
I have data that plots up a 2D image of lines separated in space. I want to filter out lines that are unconnected to any other lines. The structure of the data is 2 columns, X and Y values for endpoints of the lines plotted (this makes it easy to plot everything by just doing plot(data(:,1), data(:,2)).
Distinct lines are separated by a row that is "nan nan" (see example copied below). So each distinct line is separated by a row of "nan nan" but sometimes they connect with other lines at a shared X-Y coordinate. I want to filter out all the lines that don't share any X-Y coordinates with other lines, and keep the ones that do. Any ideas?
Thanks so much for any help!
NaN NaN
0 0.0520000000000000
0.0155560000000000 0.0364440000000000
0.0162630000000000 0.0357370000000000
NaN NaN
0.0162630000000000 0.0357370000000000
0.0169700000000000 0.0350300000000000
0.0170135700000000 0.0345319800000000
0.0170135700000000 0.0340320600000000
0.0170135700000000 0.0335321400000000
0.0170135700000000 0.0330322200000000
0.0168841800000000 0.0325493300000000
0.0168406100000000 0.0320513100000000
0.0164576500000000 0.0323726500000000
0.0166000000000000 0.0322000000000000
NaN NaN
0.0500000000000000 0.0480000000000000
0.0344440000000000 0.0635560000000000
0.0337370000000000 0.0642630000000000
NaN NaN
0.0337370000000000 0.0642630000000000
0.0330300000000000 0.0649700000000000
0.0330300000000000 0.0654699200000000
0.0330300000000000 0.0659698400000000
0.0330735700000000 0.0664678600000000
0.0331603800000000 0.0669601900000000
NaN NaN
0.0304000000000000 0.0229000000000000
0.0321000000000000 0.0240000000000000

  0 Comments

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 11 Jan 2020
Edited: KALYAN ACHARJYA on 11 Jan 2020
Is this? Lets suppose data is given as provided)
idx=find(isnan(data(:,1)));
[r,c]=size(data);
for i=1:length(idx)-1
plot(data(idx(i)+1:idx(i+1)-1,1), data(idx(i)+1:idx(i+1)-1,2),'linewidth',3)
hold on;
end
plot(data(idx(end)+1:r,1),data(idx(end)+1:r,2),'linewidth',3);

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by