How can I use function to give me a variable from an excel file?

조회 수: 3 (최근 30일)
Claudia Ganhao Gomez
Claudia Ganhao Gomez 2021년 11월 18일
답변: Srijith Kasaragod 2021년 11월 22일
I am trying to write a code that using user defined function I can get an answer from an excel file. In other words, I have an excel file that has years in the first column and values in the second, how can I use function for the user to enter a year from 1990 to 2018 and the answer to be whatever variable is assigned to that year from the excel file?
  댓글 수: 1
Rik
Rik 2021년 11월 18일
What have you tried so far?
I suspect it will be trivial if you load the data and use ismember.

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

답변 (1개)

Srijith Kasaragod
Srijith Kasaragod 2021년 11월 22일
Hi Claudia,
Following lines of code shows one of the ways you could solve your problem:
tbl= readtable('excel.xlsx');
%variable year stores the user input
%Year and Answer are the column names of the table
[outa, outb]= ismember(year,tbl.Year);
sol= tbl.Answer(outb);
Please refer 'ismember' documentation to read more on how to verify if certain elements are members of a set array.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by