Help with loading a data file into a GUI code
2 views (last 30 days)
I have a question about an operations with a GUI in matlab: I use a push button to load a data file from a folder, and the name of this file ('2DVIS_data_08_40fs') is then visualized as string in an edit text box. This is the code I use to do that:
What I want to do is: 1) show in another edit text box just the numbers included between the last underscore '_' and the last two letters 'fs', in this case 40; 2) by changing the number in this last edit text box, I want to be able to load the data file which is in the same folder as the previous one but having the number I wrote between the last underscore '_' and the last two letters 'fs' (e.g., by loading the first one I will see '40' in the edit text box, and if I change it in the box and write '120' the program has to load 2DVIS_data_08_120fs, of course if it exists!) I solved point 1) like this:
undersc_ind = strfind(nomefile_b,'_');
fs_ind = strfind(nomefile_b,'fs');
t2fs = str2double(nomefile_b(undersc_ind(end)+1:fs_ind(end)-1));
Can you help me to solve point 2) ? Thanks!
Image Analyst on 28 Sep 2014
Don't use dir as the name of your foler. dir() is a built-in function name.
Use fullfile() instead of file_b=[dir,nomefile_b];
Instead of set() just assign handles.filename_2d = nomefile_b;
If you want handles.filename_2d to be seen outside that function you'll have to return handles or use guidata().
For point 2, you'll have to do that in a pushbutton callback since when you're typing in the editbox it doesn't know when you're done typing and when to call the text changed callback until you change focus, such as by clicking on a pushbutton.