Looking to find data in a spreadsheet via user prompts

조회 수: 1 (최근 30일)
Paul
Paul 2022년 9월 21일
편집: dpb 2022년 9월 21일
So this is a basic example of the spreadsheet I'm using. Basically I want to prompt the user firstly for a P value (10-100 in steps of 10) and then a Q value (either 33 or -33). I know how to prompt the user for values and store these as variables but I then want to select the relevant test case (3001-3020) based on the values of P and Q and store it in a variable, lets say 'CurrentTestCase'. Does this make sense?
For example, lets say the user inputs P = 80 and Q = 33, I want my script to be able to select the testcase 3018 and store '3018' in the varuable 'CurrentTestCase'. Many thanks

답변 (1개)

dpb
dpb 2022년 9월 21일
편집: dpb 2022년 9월 21일
For the above correlation (or any similar that is linear in the two variables), you can simply compute the case ID; you don't need a lookup--
fnCase=@(P,Q)3000+P/10+(10*(Q>0));
If it is more generic and/or can change in ways other than obvious modifications to the above that can be derived programmatically, then just read the table and do a lookup inside it...you don't try to find the data inside the spreadsheet itself, but work on the in-memory data of the table.
tCASEIDS=readtable('YourExcelFile.xlsx');
% input P,Q, here...
CurrentTestCase=tCASIDS.TestCases(tCASIDS.("P%")==P & tCASIDS.("Q%")==Q));

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by