If statement for equal rows from two different files

1 次查看(过去 30 天)
Hello,
I have two files. Let's call them IDEAL and TEST.
Hypothetically, IDEAL contains the following data
4.1 5.3 0.02
0.4 1.0 1.11
5.8 0.4 0.85
9.0 0.3 0.34
and TEST contains
6.0 2.1 0.82
0.4 5.3 1.00
4.1 5.3 0.02
7.2 0.2 1.57
0.4 1.0 1.11
5.8 0.4 0.85
As you can tell, the files have the same number of columns but not the same number of rows, and some of the rows are identical.
I want to write an if statement in which says that
  • if TEST has rows that IDEAL does not have, plot (X,Y) as red points
  • if TEST has rows that IDEAL does have, plot (X,Y) as blue points
  • if TEST does not include rows that are in IDEAL, plot (X,Y) as green points
X and Y use several values from my files, i.e. they include several columns. I'm more interested in how to write the stament for the rows. The rows do not need to be in the same position, I just want MATLAB to know that if both files have exactly the same row, independent of position, to plot my (X,Y) as blue and if not, as red.
PS: not always all of the rows in IDEAL are included in TEST (e.g. last row in IDEAL).

采纳的回答

Alex Mcaulley
Alex Mcaulley 2019-4-4
Try this:
A = [4.1 5.3 0.02;0.4 1.0 1.11;5.8 0.4 0.85]
B = [6.0 2.1 0.82;0.4 5.3 1.00;4.1 5.3 0.02;7.2 0.2 1.57;0.4 1.0 1.11;5.8 0.4 0.85];
C = setdiff(B,A,'rows','stable') %Rows only in B
D = setdiff(B,C,'rows','stable') %Rows in A and B
  3 个评论
Alex Mcaulley
Alex Mcaulley 2019-4-4
编辑:Alex Mcaulley 2019-4-4
A = [4.1 5.3 0.02;0.4 1.0 1.11;5.8 0.4 0.85;9.0 0.3 0.34]
B = [6.0 2.1 0.82;0.4 5.3 1.00;4.1 5.3 0.02;7.2 0.2 1.57;0.4 1.0 1.11;5.8 0.4 0.85];
C = setdiff(B,A,'rows','stable') %Rows only in B
D = setdiff(B,C,'rows','stable') %Rows in A and B
E = setdiff(A,[C;D],'rows','stable') %Rows only in A

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by