Maheen Siddiqui
Maheen Siddiqui

Reputation: 539

Using matlab GUIDE to produce a modal dialog that records user inputs?

I am new to using the matlab GUIDE. I know there are some predefined dialog boxes such as inputdlg and msgbox and warndlg and so on and so forth that can easily be implemented into the command line without having to play around with too many things.

However, I was wondering whether it was possible to modify inputdlg in matlab guide? I am just trying to produce a simple dialog box that reads the user input and when the user clicks ok, it closes and records the inputs somewhere. Using inputdlg it is very easy to do so:

uiwait(msgbox(sprintf('Please enter your new references for each electrode.')));
prompt = {'Fp1','Fp1','F7','T3','T5'};
dlg_title = 'Input references';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines );

The user enters a string for each option 'Fp1', 'F7' and so on and all these answers are recorded in "answer".

Now I have 2 problems:

  1. I have 16 such inputs and if I put them all inside the same "prompt" then the dialog box runs off the screen - so I use prompt, prompt2 and prompt3 to split them up and record the answers. It works fine, but it would be better if I could arrange the input boxes side by side as you can edit/drag inside the matlab guide.

  2. I want my dialog box to look as it does in this picture with the minus sign between the 2 cells where the user will enter something into both boxes. The first box in each line is actually equivalent to the prompt that I have specified above, but in this case the user will enter the string into the first cell rather than being prompted for it.

enter image description here

But I can't seem to figure out how to do this either using inputdlg itself and altering its properties or using guide to create a custom inputdlg.

Does anybody have any advice?

Update

I have added some lines of code in the correct places and I am able to now store the user input to a variable. However, I have around 32 edit boxes and my current method means I will have 32 different inputs... I do not want this, I want them all to be recorded inside the same array.

The code I added was in the edit box callback function:

input = get(hObject, 'String')
display(input)
assignin('base','input',input);
% Save the value
handles.trial = input
guidata(hObject,handles)

This is from editbox1 and I have tried to proceed as

input = get(hObject, 'String')
A(1,:) = input
assignin('base','A',A(1,:));

but in this case it returns A as a cell which has the value entered in the last edit box.

Can anyone help?

Upvotes: 1

Views: 1908

Answers (1)

ThP
ThP

Reputation: 2332

First you should make matlab wait for the user to respond. Locate the OpeningFcn of you GUI. The last line should look like that

% uiwait(handles.figure1);

You should uncommon the line. Next, you have to resume the UI when the user clicks OK. This is done by inserting the line

uiresume(handles.figure1);

in the OK button callback. When the users clicks OK, the OutputFcn will be called. There you can return the values you need via varargout cell array. Finally, in the last line of OutputFcn, you should close your GUI using

close(hObject)

All the names I used are the matlab's defaults. If you changed any of them, modify the code accordingly.

Upvotes: 0

Related Questions