GUIDE next button inquiry

I have a series of images (let's say, 60) that are created in Matlab that are a 256 x 256 image. Therefore, I have a 256 x 256 x 60 matrix. I want to be able to create a button in GUIDE to be able to function as a "next" button, as well as a "previous" button, to view images in succession.
The initial code is:
function pushbutton1_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)
code to loop through image creation
imagesc(Z(:,:,1))
colormap(jet)
caxis([0 60])
title('Reflectivity')
handles.currentimage = 1
This initial button creates the first image. Now the button to be able to click "next" is coded as:
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if handles.currentimage < length(Z)
imagesc(Z(:,:,handles.currentimage+1))
end
however, I get the error:
Reference to non-existent field 'currentimage'.
Error in untitled1>pushbutton5_Callback (line 162)
if handles.currentimage < length(Z)
Any help would be greatly appreciated!

Answers (1)

I suggest you use a scrollbar. Set up the scrollbar to go from 1 to the number of slices. Then get the value and display that slice
scrollbarValue = handles.scrollbar1.Value;
oneSlice = Z(:, :, scrollbarValue);
imshow(oneSlice, []);

4 Comments

So I did what you recommended:
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
path =c:\'filepath';
% Pulls file names of data files
filenames = dir([path,'\*.netcdf']);
for i = 1:length(filenames)
filepathandname = [path,'/',filenames(i,1).name];
ncid6 = netcdf.open('filename','NC_NOWRITE');
[varname6, xtype6, varDimIDs6, varAtts6] = netcdf.inqVar(ncid6,0);
global_att_name6 = netcdf.inqAttName(ncid6,netcdf.getConstant('NC_GLOBAL'),2);
global_att_value6 = netcdf.getAtt(ncid6,netcdf.getConstant('NC_GLOBAL'),global_att_name6);
varid6 = netcdf.inqVarID(ncid6,varname6);
Z(:,:,i) = double(netcdf.getVar(ncid6,varid6));
end
imagesc(Z(:,:,1));
colormap(jet)
caxis([0 60])
title('Reflectivity')
handles.scrollbar1.Value = 1:length(filenames);
scrollbarValue = handles.scrollbar1.Value;
oneSlice = Z(:,:, scrollbarValue);
imshow(oneSlice, []);
However, I get the error:
Multi-plane image inputs must be RGB images of size MxNx3.
Thus, is this not possible the way this is being executed? It seems there should be a way around this..
One problem is that you're using and overwriting the reserved variable "path" with your own version. That is dangerous. Use the name "folder" instead of path.
Then, apparently it thinks Z(:,:,1) is a "multi-plane image for some reason. What happens when you do this
oneSlice = Z(:,:, 1);
whos oneSlice
imshow(oneSlice, []);
What do you see in the command window?
Thank you for your response.
I have replaced "path" with "folder" as mentioned. I have also ran the code you have provided. Everything works fine, until I slide to the next image and get the following output (in its entirety):
Name Size Bytes Class Attributes
oneSlice 384x384 1179648 double
Error using images.internal.imageDisplayValidateParams>validateCData (line 115)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 222)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in untitled1>slider1_Callback (line 218)
imshow(oneSlice, []);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)untitled1('slider1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
That doesn't make any sense to me. oneSlice is obviously a 384x384 grayscale image, not a multi-plane image. You're going to have to call the mathworks on that one.

Sign in to comment.

Asked:

on 26 Apr 2016

Commented:

on 27 Apr 2016

Community Treasure Hunt

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

Start Hunting!