Help with loading a data file into a GUI code

2 visualizaciones (últimos 30 días)
aurc89
aurc89 el 28 de Sept. de 2014
Comentada: aurc89 el 28 de Sept. de 2014
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:
direct_b='C:\Users\Name\Desktop\Rightfolder\';
[nomefile_b,dir]=uigetfile([direct_b,'*.*'],'Load file');
file_b=[dir,nomefile_b];
handles.file_b=file_b;
set(handles.filename_2d,'String',nomefile_b);
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));
set(handles.editbox2,'String',t2fs);
Can you help me to solve point 2) ? Thanks!

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Sept. de 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.
  2 comentarios
aurc89
aurc89 el 28 de Sept. de 2014
Could you plase suggest me a code which can replace the one I'm using ? I'm unfamiliar with this kind of functions. Thank you
aurc89
aurc89 el 28 de Sept. de 2014
P.S. For point 2) I need another push button I guess

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by