Help with GUI file using Guide

2 vues (au cours des 30 derniers jours)
aurc89
aurc89 le 29 Mai 2014
Commenté : aurc89 le 30 Mai 2014
Hi, I have a question about a simple GUI file; the interface is like the one in the figure.
By clicking 'Load' I load a simple matrix, called M, and plot it in the graph; I call 'wavelength' and 'spectra' the rows and the columns of M, but this is not important. Then in the four 'Edit texts' I write the values of rows and columns that I want to eliminate from the matrix M. The problem is that, when I press 'Cut' to eliminate these values, the programs doesn't recognize M anymore! The question is: how can I call , in the function 'cut', the matrix M defined in the function 'load'?
Here is the Load function, where I define M.
function Load_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
direct='C:\Users\Aurelio Oriana\Desktop\';
c=299792458;
[nomefile,dir]=uigetfile([direct,'*CALIB.dat'],'Load Calibration file');
file=[dir,nomefile];
% From PP traces
M=load(file);
axes(handles.axes1);
pcolor(M); shading interp;
xlabel('Wavelength (pixel)');
ylabel('Number of spectra');

Réponse acceptée

Geoff Hayes
Geoff Hayes le 29 Mai 2014
You can use the guidata command to save data to the handles structure. Note how in the above code, the comment for handles reads structure with handles and user data (see GUIDATA). So you can do something like this
function Load_Callback(hObject, eventdata, handles)
% etc. everything that you have above
% now save the M matrix to the handles structure
handles.M = M;
guidata(hObject,handles);
In the body of your Cut callback, the M matrix should be directly accessible from handles as handles.M.
  1 commentaire
aurc89
aurc89 le 30 Mai 2014
Thank you !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by