필터 지우기
필터 지우기

Help with loading in a GUI

조회 수: 1 (최근 30일)
aurc89
aurc89 2014년 9월 25일
댓글: Joseph Cheng 2014년 9월 29일
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 is then visualized as string in an edit text box (es. data_001). What I want to do is: 1) show in another edit text box just the last three characters of this string (in this case 001); 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 ending with the number I changed (e.g., by loading the first one I will see '001' in the edit text box, and if I change it and write '003' the program has to load data_003, of course if it exists! ); maybe I can use another push button to do this, I don't know... Thanks!

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 9월 25일
편집: Joseph Cheng 2014년 9월 25일
Since you already have a file name called lets say 'data_001.dat' and the folder path from the first file store those in handles if you're using GUIDE. with this you can access these in other functions. you can extract the file numbers like this:
%in initial load pushbutton
[handles.file_1 handles.folderpath] = uigetfile(); %if using GUIDE will save it inside the handles structure.
% file_1 = 'data_001.dat'; %just as an example to test.
pat = '_(\w*).dat';
num = regexp(file_1,pat,'tokens');
set(handles.editbox2,'string',num{:});
so now we have the numbers of the original dat file and the other edit box is populated with this. then since we saved the folderpath inside handles if we go to the editbox callback (which should run when editbox is edited then you can
%in edit box 2 callback or other pushbutton
newfilenum = get(handles.editbox2,'string');
pat = '_(\w*).dat';
handles.file_2 = regexprep(handles.file_1,pat,newfilenum)
load(fullfile(handles.folderpath,handles.file_2));
probably should go with a pushbutton as without some additional codes the editbox callback maybe run if someone clicks in and clicks out without changing anything (it's been a while so i can't remember).
  댓글 수: 2
aurc89
aurc89 2014년 9월 26일
Thank you very much! Actually the name of my file is not 'data_001' but 'VIS_measure_08_001fs', and from here I have to extract the three final numbers before 'fs', i.e. 001. How can I do ? I don't manage with your code...
Joseph Cheng
Joseph Cheng 2014년 9월 29일
then instead of using regexp then try strfind(filename,'_') where it'll give you the index of each '_'. From there you can figure out that you'll need to use the last index value+1 to index value+3.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by