How do I change the values of rows in specific columns based on another table which serves as a lookup?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alben Bagabaldo
am 16 Nov. 2019
Kommentiert: Alben Bagabaldo
am 16 Nov. 2019
Say I have two datasets loaded in Matlab. The two datasets are shown below together with the desired output (Excel screenshot is for illustration purposes only):
Let's say the first one is A.
A =
Then B should serve as the lookup table:
How do I change the values in A to the values from data B column 1 provided that the data A is equal to the data in B column 2?
Sample output should look like this:
A (values are replaced with values from B column 1) =
0 Kommentare
Akzeptierte Antwort
Stephen23
am 16 Nov. 2019
>> A = [2001,2001;2001,2003;2001,2005;2001,2006]
A =
2001 2001
2001 2003
2001 2005
2001 2006
>> B = [1,2001;2,2003;3,2004;4,2005;5,2006]
B =
1 2001
2 2003
3 2004
4 2005
5 2006
>> [X,Y] = ismember(A,B(:,2));
>> A(X) = B(Y(X))
A =
1 1
1 2
1 4
1 5
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!