MATLAB Answers

read selected data from excel datasheet using if statement

9 views (last 30 days)
Abhishek
Abhishek on 28 May 2019
Answered: Utkarsh Belwal on 24 Jun 2019
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

  0 Comments

Sign in to comment.

Answers (1)

Utkarsh Belwal
Utkarsh Belwal on 24 Jun 2019
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) ;

  0 Comments

Sign in to comment.

Sign in to answer this question.