MATLAB: How extract specific data from a large matrix and save in new matrix

data extractionmatrix

Hi, I have a matrix say"mv" ( 45×1) and another matrix called "a" (a=15252×23). Every value of 'mv' is present in 'a' (first column of a), so i want a new matrix say "b" where the data of only mv id should be there and rest should be omitted. I am writing code but unable to get desired answer. Below is the code. Please help.
for i = 1:length (mv);
if a (:,1) == mv;
mv_ramp (i,:) = a(a(:,1)== mv(i),:); % mv_ramp is new matrix where extracted data should be stored
Output: Matrix dimensions must agree (Error is coming). And Only one vehicle id data is stored in mv_ramp. Please identify my mistake. Thanks

Best Answer

  • mv_ramp = a(ismember(a(:,1),mv),:);