Need help with creating a GUI/tool.

Hello everyone,
I am working on a project and everyone uses Matlab here at my school so that is what I am also using. Beyond that I am fairly new (Started using Matlab seriously a week ago) to coding overall. I've written a few scripts for this project I'm working on, but I would like to one-up myself.
My goal is to create some sort of smart tool for what I am doing. What I am doing is, digging down into folders which contain subfolders each with the data I need to pull. The tricky part is that the data files vary in their naming convention in the different folders. That is not so much the hard part as I've got it figured out how to pull all these files one folder (with sub-folders) at a time with a single script, but what I am trying to do is create a tool. This tool/GUI (Not sure what it should actually be referred to as) would run and a box (dialogue?) would pop-up where you could choose the folder containing the sub-folders and with the code it could dig through the data and any files that had a different naming convention could then be told to grab those ones as well. The files in questions are pretty much the same just have varying numbers at the end like studentname_id_cohort_0001, studentname_id_major_0001, where the numbers on the end are a count of the same name. The varying naming structure can be something like id_major_lastname.firstname0001, it is all wacky, no one standardized this nonsense.
I also want to be able to interface this tool with another script that actually converts the file format. I've been doing a lot of research, tutorials, surfing around here, but haven't been able to find anything that I feel confident enough to take my first step with. Any pointers or tips in the right direction would be most helpful. Also, I'm using MATLAB 2016.
Thank you very much,
LOV

12 个评论

Hey Lov,
from your above mentioned question, what I understood is that, you want to create a GUI where you can provide the path of parent folder. and when you click on pushbutton it should run your scripts and should produce the results... right ???
if this is correct understanding then let me know..so that I can give a proper solution..
Shameer,
Yes, I believe what you are saying is what I am after. I want to be able select a parent folder that contains multiple subfolders which also sometimes contain other subfolders where, within some those folders, the data I need to grab and convert exists. Said data like I mentioned before has multiple naming conventions so I want the tool thing to be able to identify files that don't follow the convention and perhaps prompt me with a box that has the option to add items of such to its search and grab. There are also some files that follow the naming convention that are sometimes redundant and it would be nice to have perhaps a toggled option to leave out certain files that have something like 'GPA' anywhere in the name of said file.
Hopefully I'm not confusing you or anyone else. Please ask more questions if you need help helping me and I will try and answer them.
Thank you!
Lov,
So for creating the above shown GUI, use 'guide' command. using 'guide' command you can create any type of GUI as per your requirement. just type 'guide' into MATLAB command window and see.
now after creating the GUI as shown above, open .m file of GUI and into callback of pushbutton 'Results' add following code.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% to fetch the folder path mentioned into above editbox
folderPath = get(handles.edit1,'String');
% call your .m files to perform the operation you want
abcd(folderPath);
Here, I believe you already have the other .m files which provides the proper results. so replace above 'abcd' with your main file name.
(if you dont have the .m files OR if your .m files throwing any error, let me know, give me the proper requirement so that I can help you.)
Shameer,
Thank you, I will try this out and get back to you. If it works than I will also let you know.
Sincerely,
LOV
Shameer,
Is there a way to set this up so that the folder path can be selected? Similar to how something like this might have a 'browse' button that calls the windows explorer window for a file or folder to be selected.
Also, let's say for now that I don't have the other .m files yet. Right now I just want the GUI to work as dir selector, once I figure that out, I'll try to set up the other button that will run my script against the selected folder to convert and compress the data and store it in a new location.
Hopefully this helps, if I'm not being clear on what I need, please let me know and I'll try to explain more. Thank you so much for your help!
-LOV
Yes, it is possible..
Check for the command "uigetdir". This will help you..
So instead of copy-pasting the path in edit box, you can put this command into callback of pushbutton, so that it will ask for folder selection and will store and use that folder path..
So in my above given example code, just replace command
folderPath = get(handles.edit1,'String');
with
folderPath = uigetdir;
Ok, great! Will that put the selected folder path into text in the box above to show the folder path selected?
When I'm ready to link this GUI with my script I just add the line myscript(scriptPath); where scriptPath = where my script is?
I apologize if I am asking overly simple questions, as I am still brand new to scripting/programming/MatLab in general.
I thank you for your continued support.
-LOV
Yes, to display the selected folder path into editbox (of my very first GUI snapshot), you need to use set command in same callback of push button as follows..
% callback of push button
folderPath = uigetdir;
set(handles.edit1,'String',folderPath);
abcd(folderPath) ---- % to calling your script
% end of callback of push button..
L
L 2016-6-20
编辑:L 2016-6-20
I deleted my previous comment because I was able to figure it out. I read that you said set command and in the code it says get.
I've attached my GUI code in addition to this picture;
I would like the "begin conversion" button to be the one that kicks of my other scripts, but I'm not sure how to tie them together. The other script basically starts with my dir hard coded along with what file type to look for, where to put it after conversion, what specific file names to look for and pull. The question is, how do I make this GUI insert the defined folder dir into the other script? Assume the output will not change.
Thank you so much,
LOV
Sorry that I have mentioned get() command, it should be set(). I corrected this in my above mentioned comment.
Now in your GUI, under callback of 'Browse' push button.. put following to command..
folderPath = uigetdir; % to select the directory
handles.folderPath = folderPath; % variable to access in other callback
set(handles.edit1,'String',folderPath); % to set edit text with folder path
guidata(hObject, handles); % to save the GUI handle data.
Now in callback of push button 'Begin Conversion', put following command..
abcd(folderPath) ---- % to call your script
Please note: Your other script you need to modify, so that it will take variable 'folderPath' as input argument for further process.
Hello Shameer,
I seem to be having trouble with the abcd(folderPath) part. It keeps saying that it is an undefined variable or function. Instead of abcd I'm putting the name of my .m file ex: testcode1(folderPath) and it is not liking that.
Here is the error:
Undefined function or variable 'testcode1'.
Error in smart_tool>pushbutton1_Callback (line 86) testcode1('folderPath');
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in smart_tool (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)smart_tool('pushbutton1_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback
I'm getting close to getting this tool to work, its just a matter of getting my other script to work with the tool.
Thank you again for all of your help!
-LOV
1. First check the name of the file is correct..that is 'testcode1', and should be same at all places.
2. The file 'testcode1.m' should be present in your current directory, along with all other support files, where the .fig file is present
3. make sure that your file 'testcode1' also have the single input argument.
4. use "testcode1(handles.folderPath);" instead of "testcode1(folderPath);" for calling your code from callback of pushbutton 'Begin Conversion'
Let me know if you face any issue..

回答(0 个)

此问题已关闭。

产品

提问:

L
L
2016-6-16

关闭:

L
L
2016-7-8

Community Treasure Hunt

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

Start Hunting!

Translated by