keep the same row data from two matrix
Ältere Kommentare anzeigen
i have a total data matrix a(253*2), now i just want to keep the data from b(223*1) and get the whole data is c(223*2), which means that keep the same data between a&b. how should i do?
3 Kommentare
Mathieu NOE
am 25 Mär. 2021
hello
you mean c would be the first 223 rows of a ?
then this is it :
c = a(1:223,:);
zhengyang shang
am 25 Mär. 2021
Mathieu NOE
am 25 Mär. 2021
OK so you have to use find the get the similar values from col 1 in a and b
ind = find(a(:,1) == b);
c = a(ind,:);
Antworten (1)
Jan
am 25 Mär. 2021
This is a job for intersect or ismember.
[~, ia, ib] = intersect(a(:, 1), b);
c = [b(ib), a(ia, 2)]
2 Kommentare
zhengyang shang
am 25 Mär. 2021
Jan
am 25 Mär. 2021
I cannot follow you. The tables do share at least some common data. So my code is expected to work. If it does not work for you, please post your code.
Kategorien
Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!