MATLAB: uiopen AND get the name of that file? - matlab

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).

Related

Matlab Calling 'Import Data' with GUI Button

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.

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

I Want Users Browse The File, But It Affects to My Script

I'm doing with MATLAB.
I have a file named 'cobat'. Cobat is a *txt file, tab delimited, consisted of 3 coloumns, so it's a table. I load it manually into this script:
I want users browse their own file. How can I do it? Is this code correct:
[filename pathname] = uigetfile(('.txt'), 'Browse Your File')
Here are my problems:
I think it is only for text file, not tab delimited (table). I think I have to use uitable, but I don't understand how to implement it, because the file (cobat) should be loaded.
And, if it has been implemented, I can't write 'cobat' in my script, like this:
[g c] = kmeans(cobat,k,'dist','SqEuclidean'); y = [cobat g]
Then I have to change 'cobat' to what name?
Thank you.
You are on the right track. After locating the file you need to load it:
load([pathname filesep filename])
If file name is cobat (or cobat.txt), it will create a matrix called cobat in the workspace with the content of the file.

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)