Reputation: 427
I have a question about how can I write a code to create a GUI in Matlab. I've created the graphic interface with a simple button. I want that, pressing that button, load a text file and after a loop, load an image and create the different bands (this process is because it's a multispectral image with different bands). This code works well if I execute on a .m file. This is the code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
Dates=load ('C:\Users\Desktop\dates.txt');
NombImages=load ('images.txt');
Nimages= numel(Dates);
fileimg=NombImages(1);
fileistr=int2str(fileimg);
image1 = imread(fileistr);
size=size(imagen1); nrows= size(1);
ncolumns= size(2);
nbands= size(3);
Images = zeros(nrows, ncolumns, nbands, Mimages, 'uint16');
imagess = zeros(nrows, ncolumns, nbands);
for image= 1: Nimages
fileimg=NombImagen(image);
fileistr=int2str(fileimg);
imagess = imread(fileistr);
Images(:,:,:,image)=imagess;
end
DN= double(Images);
Band1 = Images(:,:,1);
Band2 = Images(:,:,2);
Band3 = Images(:,:,3);
end
% 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)
Maybe it seems a bit complicated but it's because of the format of the images (16 bits, etc.). I don't want to visualize the bands, only load it with that code.
Any help would be appreciated. Thanks in advance,
Upvotes: 0
Views: 762
Reputation: 1832
here we go:
you recieve an error-message, which indicates, that there is an "end" at the end of your function (the pushbutton-callback-fcn).
In Matlab it is possible to end functions without ending them with an end :)
When using GUIDE for example, this is the default. GUIDE creates functions without ending them with "end".
So the problem is: if you put an "end"-statement somwhere to end a function, Matlab is expecting an end after EVERY function!!
In your special case:
remove the "end" at the end of your code:
...
Band1 = Images(:,:,1);
Band2 = Images(:,:,2);
Band3 = Images(:,:,3);
end%<-this one :)
Another option of course is, to an end after every function...
edit
to store data within a GUI you can (or should) use the handles-structure. How to use it in detail is explained here:
A short version:
store data within the handles-structure like this:
handles.myVar = ...
and dont forget to update the structure by this command:
guidata(hObject,handles)
For you it should look like:
handles.Band1=Band1; %or directly: ...=Images(:,:,1);
...
guidata(hObject,handles)
and later on you can retrieve the data within another function (that knows about the handles-structure of course!) just like this:
handles.Band1
Upvotes: 1