Help with GUI file using Guide

1 Ansicht (letzte 30 Tage)
aurc89
aurc89 am 29 Mai 2014
Kommentiert: aurc89 am 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');

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by