Comparing user input and dataset to select appropiate value

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by