MATLAB: Reading multiple columns of an excel sheet to output a range of values. Please see the example

excelindexingmultiple arraysmultiple columns

Hi,
I am reading multiple columns of an excel sheet, where two columns are a set.
Columns from A to Z, which are sets of AB, CD, EF, GH… YZ
Col A: 1 2 3 4 5 6 7 8 9 10
Col B: 0 3 5 15 30 40 55 85 95 100
I need the output values of ColA and ColB, based on i) ColB>5 & ColB<95 ii)ColB>15 & ColB<85
Answer here would be
Casei)
Col A: 3 4 5 6 7 8 9
ColB: 5 15 30 40 55 85 95
Caseii)
ColA: 4 5 6 7 8
ColB: 15 30 40 55 85
I am able to get these values with the following code. However, I am looking for output of other columns as well like for (ColC,ColD), (ColE, ColF)… (ColY, ColZ). Also the size of the the range for all 13 pairs.
D=xlsread('data.xlsx','Sheet3');
c1=D(:,1);
c1(isnan(c1))=[];
c2=D(:,2);
c2(isnan(c2))=[];
c2t90=c2>=5 & c2<=95;
C2t90=c2(c2t90);
C1t90=c1(c2t90);
frd1t90=[C1t90 C2t90];
dt1t90=size(C1t90);
c2t70=c2>=15 & c2<=85;
C2t70=c2(c2t70);
C1t70=c1(c2t70);
frd1t70=[C1t70 C2t70];
dt1t70=size(C1t70);
Look forward to an output.
Thanks,

Best Answer

Hi,
I understand that you wish to look for output of other columns as well.
What you can try doing is to write a loop which accesses all the columns of D (the matrix which stores data.xlsx Sheet3) and computes the values of columns based on the conditions specified.
An example -
D=xlsread('data.xlsx','Sheet3')
for i=1:2:26
c1=D(:,i);
c1(isnan(c1))=[];
c2=D(:,i+1);
c2(isnan(c2))=[];
c2t90=c2>=5 & c2<=95;
C2t90=c2(c2t90);
C1t90=c1(c2t90);
frd1t90=[C1t90 C2t90];
dt1t90=size(C1t90);
c2t70=c2>=15 & c2<=85;
C2t70=c2(c2t70);
C1t70=c1(c2t70);
frd1t70=[C1t70 C2t70];
dt1t70=size(C1t70);
end