If statement for equal rows from two different files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marisabel Gonzalez
le 4 Avr 2019
Commenté : Marisabel Gonzalez
le 4 Avr 2019
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 commentaires
Réponse acceptée
Alex Mcaulley
le 4 Avr 2019
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 commentaires
Alex Mcaulley
le 4 Avr 2019
Modifié(e) : Alex Mcaulley
le 4 Avr 2019
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!