I'm trying to initialize an array of rectangles as my gui opens (all with their 'Visibility' set to 'Off').
First, create the array to hold the objects:
handles.refRec = gobjects(21, 1);
Then, call my function that draws the initial gui window:
... Prior code reads the curSpec from an excel file and uses a file exchange file to set the plot colors depending on its sizeopenRefSpecAnalysis(handles.curSpec, handles.plotCol, handles.refRec);function openRefSpecAnalysis(curSpec, plotColors, rect) drawSpectra(refPlotAxes, curSpec); % Function works fine, not recreated here
drawRect(refPlotAxes, plotColors, rect); % Function not working, recreated below
openRefAnalysisWind(plotColors); % Function works fine, not recreated hereend % Breakpoint 2 placed here
function drawRect(curAxes, plotCol, rect) set(plCallWind, 'CurrentAxes', curAxes); for cnt = 1:length(plotCol(:, 1)) rect(cnt, 1) = rectangle('Position', [0 0 1 1], 'FaceColor', plotCol(cnt, :), 'Visible', 'Off') endend % Breakpoint 1 placed here
When I hit breakpoint 1, rect is filled with 21 invisible rectangles. I use get(rect(1, 1)) at the command line to make sure it's a rectangle object with the correct position, visible properties. However, when I hit breakpoint 2, rect is now an array of root objects (just as when it is first created by gobjects). My understanding is that graphics objects are passed as handles (by reference?) and not as values, and so the modifications to rect in drawRect should be seen in openRefSpecAnalysis after drawRect executes.
Best Answer