1
votes

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?

1
Can you explain further your issue using GUIDE to create this custom dialog box? It seems like you have the layout just fine.excaza
@excaza when I run the gui it produces that picture above but clicking ok doesn't close it and the entries I put it in just come up as one number "239". I have read a tutorial on the matlab website about modal dialog and they teach you the bits of code you need to add in for it to close.. so will I need to program every single object I add?Maheen Siddiqui
See if this blog post is helpful. Otherwise I will try and write up an example later this morning.excaza
@excaza yes the blog post was helpful, particularly about the part at the end of using code from other existing forms. I wanted to use the density and volume one existing GUI and use its code because it takes inputs from the user and stores them, but I keep getting the same error for some reason. I will post the error inside my question under Edited.Maheen Siddiqui
@excaza by "density and volume existing GUI" I meant the existing GUI template with uicontrols.Maheen Siddiqui

1 Answers

0
votes

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.