Use logic index to sort back to original data that are logic 1.

조회 수: 4 (최근 30일)
Yang Hu
Yang Hu 2023년 10월 11일
댓글: Yang Hu 2023년 10월 29일
Hello community,
I am working sorting out data that has logical value is 0. I am trying to explain what I wanna do clearly and consisely.
I have a original data set in excel that is attached 'test1gofcells.xlsx", the first column is x coorindates and second is y coordinates of each sheet. After some calculation, the data is output as 'IndiMSD', I use the following code to define [100 100000] as lower and upper boundary to include the data (last element of each columns) within and exclude data without.
I already do the logic to identify the sheets that I dont want to include (logic = 0), so I have a row matrix (ix) in logic numbers of 0 and 1. Now I want to use ix to trace back to the sheets in 'test1gofcells' only are logic = 1, and output those sheets.
This is my code to compare 'IndiMSD' to [100 100000] and do the logic:
ix=iswithin(IndiMSD(end,:),100,100000);% get data that are only between 100 and 100000;
% IndiMSD is calculated from original file
IndiMSD_within = IndiMSD(:,ix); %get columns that are only logic = 1;
I don't know how to use ix to get back to the columns within 'test1gofcells' with logic = 1. Please help!
Thank you.
  댓글 수: 1
dpb
dpb 2023년 10월 11일
tT=readmatrix('test1gofcells.xlsx');
tI=readmatrix('IndiMSD.xlsx');
whos t*
Name Size Bytes Class Attributes tI 97x116 90016 double tT 97x2 1552 double
But "test1gofcells" has only two columns whereas 'IndiMSD" has 116. Something can't be right here or we're not following and don't have enough code to see what transpired from start to finish.
However, presuming you start with more (or as many) columns in "test1gofcells" as you end up with, this is a time where you may need to apply find to the logical vector ix to return the absolute number(s) of the selected columns.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2023년 10월 11일
편집: Matt J 2023년 10월 11일
opts=detectImportOption('test1gofcells.xlsx');
clear data
for k=numel(ix):-1:1
opts.Sheet=k;
if ix(k)
data{k}=readmatrix('test1gofcells.xlsx',opts);
end
end
data=cat(3,data{:});

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by