Clear Filters
Clear Filters

Comparing user input and dataset to select appropiate value

3 views (last 30 days)
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,

Accepted Answer

Hugo
Hugo on 10 Jun 2013
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,

More Answers (1)

Robbert
Robbert on 10 Jun 2013
This worked, although I had to use str2double instead of str2num.

Community Treasure Hunt

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

Start Hunting!