Hello all!
I am trying to create a GUI where the slider updates the image slice displayed. I've looked at various examples but am not totally successful yet. With the code below, the slider displays the correct image at the first (1) and last (33) positions. However, any other location gives the error message "Subscript indices must either be real positive integers or logicals."
% --- Executes just before MagicWandGUI is made visible.
function MagicWandGUI_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MagicWandGUI (see VARARGIN)
% Add gen MATLAB path
addpath(genpath('C:\Users\Student\Desktop\DECT_research'));% Load Iformatted40 {n} where n1:33; target slice is 17
load('C:\Users\Student\Desktop\DECT_research\Code\Iformatted40.mat')% Set number of slides
IM_MAX = 33;% Set default IMG to zeros
axes(handles.axes1)imshow=zeros(512);% Choose default command line output for MagicWandGUI
handles.output = hObject;handles.Iformatted40 = Iformatted40;handles.IM_MAX = IM_MAX;% Set limits on slider
set(handles.slider1, 'Min', 1);set(handles.slider1, 'Max', handles.IM_MAX);set(handles.slider1, 'Value', 17);set(handles.slider1, 'SliderStep', [1/handles.IM_MAX , 10/handles.IM_MAX]);% Update handles structure
guidata(hObject, handles);% --- 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)SliderLocation = get(handles.slider1,'Value');axes(handles.axes1)Iformatted40 = handles.Iformatted40;imshow(Iformatted40{SliderLocation}, [-335 223])Set(handles.slider1,'Value',SliderLocation)
The curious thing is that the slider does take 33 steps to go from one end to the other. Where have I made a mistake? Also, I intended for the axes to be all dark (zeros) upon loading, but that also isn't happening.
Thank you so much!
Best Answer