How to get the value corresponding to the data in an excel file
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am trying to write an algorithm that calculates the values entered by the user and obtains a result, and prints the value in the 1st column corresponding to this result.
For now, let's ignore the initial calculations and get the result of the calculation directly from the user. This is how I did it;
T = readtable('katalog.xlsx');
in = input('Enter Input\n','s');
For example, the user found the answer 13.2 as a result.
Matlab should compare this result with the closest value in the excel file and output the text in the 1st column corresponding to that value.
You can check my excel file in the attachment.
Despite doing a lot of research, I couldn't find exactly how to do this. If you can help me with this, that would be great.
댓글 수: 0
답변 (1개)
Arif Hoq
2022년 3월 30일
try this:
A=readtable('katalog.xlsx','ReadVariableName',false);
B=table2array(A(2:end,2:end));
D=str2double(string(B));
userinput=36.1; % you can defined in a function "input"
[~,~,idx]=unique(round(abs(D-userinput)));
minVal=D(idx==1)
[row col]=find(D==minVal);
output=A(row+1,1)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!