read selected data from excel datasheet using if statement

2 次查看(过去 30 天)
if have a excel file " testfile" for which i have to slect some data using if statement
i want to read column 4th, 5th and 9th coloumn of this file starting from where coloumn 1 values are >=14 and read it till where cloloum 1 value is <= 16
I have tried the code but it didnot work
A = xlsread('testfile.xlsx')
if (A(:,2)>=14)
then
if(A(:,2)<=15)
then
B = A(:,4);
C = A(:,5)
D = A (:,9)
end
end

回答(1 个)

Utkarsh Belwal
Utkarsh Belwal 2019-6-24
A(:,2) >= 14 will give a matrix of 0s and 1s, if statement will execute only if A(:,2) >= 14 returns a matrix which has all 1s and according to your xlsx sheet that is not the case so if statement will never be true. Although you can try this code,
A = xlsread('testfile.xlsx') ;
ind = A(:,1) >= 14 & A(:,1) <= 16 ;
B = A(ind , 4) ;
C = A(ind , 5) ;
D = A(ind , 9) ;

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by