Assuming that you are using GUIDE to develop your GUI, suppose you have your callback for push button 1, tagged as push1 as
function push1_Callback(hObject, eventdata, handles)
[filename,path] = uigetfile('*fs.dat');
if ischar(filename)
fullpathToFile = fullfile(path,filename);
handles.myfile = fullpathToFile;
set(handles.edit1,'String',filename);
fileId = char(regexp(fullpathToFile,'_[0-9]+fs','match'));
fileId = fileId(2:end-2);
set(handles.edit2,'String',fileId);
guidata(hObject,handles);
end
The above use uigetfile to allow the user to select the fs.dat file to load. The name of the file is saved to the *handles structure for future reference. The set command is used "write" the filename (and later file integer ID) to the edit text widgets. We then use regexp to match in the string for an integer (with one or more digits, hence the +) between and underscore and the 'fs' text. Finally, we save the updated handles structure with guidata.
To go the other direction, in your other callback, you will want to use the get call to grab the integer (that the user has changed) from the edit2 widget, and you can use regexprep to replace the original ID with this one
newFileId = ['_' char(get(handles.edit2,'String')) 'fs'];
handles.myfile = regexprep(handles.myfile,'_[0-9]+fs',newFileId);
guidata(hObject,handles);
Given the above, you should be able to construct your two callbacks to do what you want.
Best Answer