Index from one vector to different sized vector

1 Ansicht (letzte 30 Tage)
koscar
koscar am 12 Sep. 2020
Kommentiert: koscar am 20 Nov. 2020
I have a 582x1 column vector and a 3190x2 matrix. I want to extract only those rows of the matrix whose column 1 entry has the same value as any entry in the 582 vector. I can't figure out how to index in this way. I tried changing the size of the column vector to 3190, but it still only compared the entries with the same indexes.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Sep. 2020
selected_rows = array3190(ismember(array3190(:,1), vector582),:);
  1 Kommentar
koscar
koscar am 20 Nov. 2020
Thanks. I found that the interp function worked well for what I was trying to do.
data1 = interp1(array3190_col1,array3190_col2,vector582)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam am 12 Sep. 2020
% v1 the first vector
% v2 the matrix
[~, ~, i2] = intersect(v1, v2(:,1));
newMatrix = v2(t2,:);

Kategorien

Mehr zu Matrix Indexing 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!

Translated by