If statement for equal rows from two different files
1 回表示 (過去 30 日間)
古いコメントを表示
Marisabel Gonzalez
2019 年 4 月 4 日
コメント済み: Marisabel Gonzalez
2019 年 4 月 4 日
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).
0 件のコメント
採用された回答
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
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!