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