extracting subset of rows from columns in multidimensional matrix

조회 수: 8 (최근 30일)
Hi, I have a 5269x7x1526 matrix/tensor and I need to extract data based on criteria from column 5 of the middle index. When extracting this data I need to keep the data entries from columns 5 and 2 together because I will need to plot them. For example, column 2 of the middle dimension of my matrix/tensor is temperature data and column 5 is location data. So far this is what I have:
for i = 1:num_time_steps
range = T_all((T_all(:,5,i)>=0.02) & (T_all(:,5,i)<=0.03),:);
end
Here I am trying to extract data associated with column 5 that is between 0.02 and 0.03 but when I run this loop I get a bunch of zeros out except for the last 10 or so columns which do not give me meaningful information.
Does anybody have any ideas of how I can extract paired data that lies between 0.02 and 0.03 of the 5th column of my multidimensional matrix/tensor? I need to keep the location and the temp data together, columns 5 and 2.

채택된 답변

Adam Danz
Adam Danz 2018년 7월 30일
편집: Adam Danz 2018년 7월 30일
I think this is what you're after.
You are on the right track. In the loop below 'idx' is a logical vector identifying all rows where column 5 is between your bounds. Use that index to extract rows of columns 5 and 2.
for i = 1:num_time_steps
idx = (T_all(:,5,i)>=0.02) & (T_all(:,5,i)<=0.03);
pair1 = T_all(idx, 5, i);
pair2 = T_all(idx, 2, i);
end
Alternatively if you'd like the paired values in 1 matrix
for i = 1:num_time_steps
idx = (T_all(:,5,i)>=0.02) & (T_all(:,5,i)<=0.03);
pairs = T_all(idx, [5,2], i)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by