Matlab Calling 'Import Data' with GUI Button - matlab

I'm working in a GUI in Matlab R2014b that uses some data from a txt file, so i want to call the 'Import Data' window to permit the user select the data from a file when pushing a button. Is there a way to do this?

The function uiimport is used for importing data interactively. This seems to be what gets called by Matlab's toolbar's "import data" button.
Excerpting from the documenatation,
uiimport opens a dialog to interactively load data from a file or the clipboard. MATLABĀ® displays a preview of the data in the file.
uiimport('-file') presents the file selection dialog first.
S = uiimport(___) stores the resulting variables as fields in the struct S.
So, just set
uiimport('-file');
as the button's callback.

Related

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:
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.
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.
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?
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.

Open dialog box for name and file type to be created MATLAB

I try create a .txt file with define name in dialog box when click in button Export Parameters (gui Matlab) but can not.
Only can create new file with names already defined, as we see in the following code.
function export_par_Callback(hObject, eventdata, handles)
f=handles.f;
d=handles.d;
gamma=handles.gamma;
dlmwrite('PARAMETERS.txt', [f',gamma',abs(d)',imag(d)'], 'delimiter', '\t','newline','pc')
[f',gamma',abs(d)',imag(d)'] is a simple matrix
I only need the dialog box before saving nem file
please read the documentation of uiputfile

MATLAB: uiopen AND get the name of that file?

I have a GUI that has pushbuttons. You push the button, it allows you to choose a file to open then loads that file into the workspace using uiopen('load'). This part works fine:
Then I would like it to return the name of the file it just opened, so that I can use it for telling the next part of the program which data to look at, and to get the name of the opened file to display in an edit box in the GUI itself. First issue more vital than second. Any help would be appreciated
thanks
Actually the function 'uigetfile' is usually used for openning standard dialog box for retrieving files, and the format is like:
filename = uigetfile
or
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
This function, displays a modal dialogbox that lists files in the current folder and enables you to selector enter the name of a file. If the file name is valid and the fileexists, uigetfile returns the file name as astring when you click Open. Otherwise uigetfile displaysan appropriate error message, after which control returns to the dialogbox. You can then enter another file name or click Cancel.If you click Cancel or close thedialog window, uigetfile returns 0.
one example could be:
[FileName,PathName] = uigetfile('*.m','Select the MATLAB code file');
Also, you can use 'uigetdir' for doing the same for directories.
In addition, you can check this link: for matlab
You can use uigetfile to get the name of the file and open it using load(filename).

rename ui file in matlab

I am working on a gui with guide in matlab. Inbetween I devided to name the file
different and renamed it. I also renamed all functions to the new filename in the .m file
and all objects in he .fig file.
However when I start the application I still see this error
??? Undefined function or method 'uiSchwingungen' for input arguments of type 'char'.
Error in ==>
#(hObject,eventdata)uiSchwingungen('edit1_CreateFcn',hObject,eventdata,guidata(hObject))
Where uiSchwingungen is the old not existing filename.
Where is this code section hidden (It is not in the .m file, and the .fig is binary)
You need to open the .fig in GUIDE, right click on an element (like a button), go into property browser, look for the CallBack property, click on its field to edit it, and you will find the text saying
#(hObject,eventdata)uiSchwingungen('edit1_CreateFcn',hObject,eventdata,guidata(hObject))
You will need to replace uiSchwingungen with the name name of that element (which will be in the Tag field of the Property Inspector).
Go through all the buttons, text boxes, etc., as this mistake probably will have occurred more than once.

Programming of 'edit text' & 'pushbutton' components of a GUI in MATLAB's GUIDE tool

I have a .m file written with definition of input & output variables along with calling of other function files which calculate the numeric output from provided numeric input.
I want to build a GUI in MATLAB for the same.
What I require is coding information for
1)Retrieving numeric data from 'edit text' component & pass this data assigned as input data
2)Set an action by clicking push button to run the program, calculate output from input & display the numeric values as output.
As far as I understand your question, it's pretty easy. I hope this will be helpful.
1. open guide by typing guide in command window.
2. click blank gui
3. guide window will open
4. click and drag a push button and an edit text.
5. click the editor
6. save your file
7. go to the follwing function
function pushbutton_Callback(hObject, eventdata, handles)
and write down this code below.
str = inputdlg('Enter numbers (seperated by commas)');
num = str2num(str{1});
a=num(:,1);
b=num(:,2);
ans=a+b; //or whatever you want to do!
caption = sprintf('your answer is %.2f',ans)
set(handles.edit,'string',caption)