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:
[nomefile_b,dir]=uigetfile([direct_b,'*.*'],'Load file');
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!

Accepted Answer

Image Analyst
Image Analyst on 28 Sep 2014
Some tips
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.
aurc89 on 28 Sep 2014
P.S. For point 2) I need another push button I guess

Sign in to comment.

More Answers (0)


Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by