How do I using logical values to write 'NAN' to non-existing data?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Stephen Tete
am 8 Nov. 2022
Bearbeitet: Stephen Tete
am 8 Nov. 2022
I have a data set with non equal lengths
A = B =
H m lat H m lat
0 2 -90 0 1 -90
0 2 -89 0 1 -89
0 2 -88 0 1 -87
0 2 -87 0 1 -86
0 2 -86
I want to query using the lat of A to find missing lat in B and write 'NAN' in that row
so that the sizes become the same like this; I want to use this idea for a large data set
B=
0 2 -90
0 2 -89
NAN NAN NAN
0 2 -87
0 2 -86
0 Kommentare
Akzeptierte Antwort
Rik
am 8 Nov. 2022
You can use ismember:
A=[ones(5,2).*[0 2] (-90:-86).'];
B=[ones(4,2).*[0 2] [-90;-89;-87;-86]];
new_B=nan(size(A));
[~,rows]=ismember(B(:,3),A(:,3));
new_B(rows,:)=B;
new_B
4 Kommentare
Rik
am 8 Nov. 2022
You have posted code, but you didn't explain how the output is different from what you want.
Note that this code will overwrite any values that occur multiple times in later elements of A.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!