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 个评论
Shameer Parmar
2016-6-16
编辑:Shameer Parmar
2016-6-16
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..

L
2016-6-16
Shameer Parmar
2016-6-17
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.)
L
2016-6-17
L
2016-6-20
Shameer Parmar
2016-6-20
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;
L
2016-6-20
Shameer Parmar
2016-6-20
编辑:Shameer Parmar
2016-6-21
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..
Shameer Parmar
2016-6-21
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.
L
2016-6-23
Shameer Parmar
2016-6-23
编辑:Shameer Parmar
2016-6-23
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 个)
此问题已关闭。
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
