Comparing user input and dataset to select appropiate value

1 回表示 (過去 30 日間)
Robbert
Robbert 2013 年 6 月 10 日
I am writing a script which users can run to analyze their data. It involves a point where user input is required, because measurements have been made on different settings. I know how to ask for user input, but how can I compare the answer to my dataset and then select the appropiate value?
The relevant part of the script is:
prompt = {'Gemeten bij pompstand:','Tijd bij steady state in seconden:'};
dlg_title = 'Input';
num_lines = 1;
def = {'0.8','700'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
The dataset is as the following. answer(2,1) can just be a numeric value, I don't have a dataset for that one. Only answer(1,1) has to be compared and selected.
0.2 450
0.4 420
0.8 380
1.0 350
1.5 320
Thanks in advance,

採用された回答

Hugo
Hugo 2013 年 6 月 10 日
How about using find after conversion to numeric value of the answer?
ansnum=str2num(answer(1,1));
k=find(dataset==ansnum);
When dataset is the first column of the data that you show, k will give you the position where the user input matches the dataset.
Best regards,

その他の回答 (1 件)

Robbert
Robbert 2013 年 6 月 10 日
This worked, although I had to use str2double instead of str2num.

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by