How do I use an if statement to check if a data is present on a excel sheet?

조회 수: 3 (최근 30일)
Adithya Narasimhan
Adithya Narasimhan 2021년 3월 10일
편집: Adam Danz 2021년 3월 12일
I want to create an if condition that should check if student name and ID is present in the excel sheet.
If it is present it shoul execute the code i want it to run.
I am trying xlsread but is not working for me any suggestion?

답변 (1개)

Adam Danz
Adam Danz 2021년 3월 10일
At the top of the documentation page for xlsread there is warning that xlsread is not recommended and it suggests alternative functions (readtable, readmatrix).
If you're checking that a particular header (variable name) exists, you can use those function to read in just the header row(s).
If you're checking if a paricular name and ID exists you'll need to read in the entire table and the search the name and ID columns (hint: isequal, strcmpi, ismember).
If you get stuck and have any problems, show us where you're at and describe the issue.
  댓글 수: 2
Adithya Narasimhan
Adithya Narasimhan 2021년 3월 10일
Can I use somthing like
a = input('Enter name: ');
if a == readtable('StudentIDverify.xlsx')
does this work?
Adam Danz
Adam Danz 2021년 3월 10일
편집: Adam Danz 2021년 3월 12일
Not quite.
Try reading in the table using readtable and look at what it produces.
'a' will presumably be a character vector but the readtable function will read in an entire table.

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

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by