How to update 3-D plot after every loop?

I have a sequence of images (200 images) that I need to analyze. When I run my program, 200 figures in separate windows appear. Is there any way that I can have all of the figures from the loop in the same window? That is, the figures update one after the other.
if true
% code
end
fileFolder = fullfile(matlabroot, 'toolbox', 'images', 'imdata');
dirOutput = dir('/Users/Name/Documents/MATLAB/image_*.tiff');
fileNames = {dirOutput.name}'
numFrames = numel(fileNames)
figure(); hold on
for p = 0001:numFrames
sequence(:,:,p) = imread(fileNames{p});
%intensity plot info
[x,y] = size(sequence(:,:,p));
X = 1:x;
Y = 1:y;
[xx,yy] = meshgrid(Y,X); %intensity profile in 3-D space
i = im2double(sequence(:,:,p)); %convert images to double precision
%max and FWHM x and y from plot
[mz,k] = max(i(:));
[ix,jy] = ind2sub(size(i),k); %determine x and y at max intensity
[ix,jy,mz]; %max intensity coordinates
%max intensity coordinates in microns
%pixel size is 6.45x6.45 microns
ix = 6.45*ix;
jy = 6.45*jy;
[ix,jy,mz];
mhz = 0.5*mz;
[ihx,jhy]=ind2sub(size(i),k); %determine x and y at half max intensity
[ihx,jhy,mhz]; %half max intensity coordinates
FWHMx = abs(ix-ihx)*2; %full width at half max in x direction
FWHMy = abs(jy-jhy)*2; %full width at half max in y direction
%table of data from plot
f = figure;
data = [ix,jy,mz,FWHMx,FWHMy];
colnames = {'X(Zmax) [um]', 'Y(Zmax) [um]', ...
'Zmax/Max Intensity', 'FWHMx [um]', 'FWHMy [um]'};
t = uitable(f, 'Data', data, 'ColumnName', colnames, 'ColumnWidth', {120});
t.Position(3) = t.Extent(3);
t.Position(4) = t.Extent(4);
%make subplot of table and intensity plot
subplot(2,1,1) = mesh(xx,yy,i); colorbar;
title('Intensity of Beam Image as a Function of Pixel Position');
xlabel('X(pixels)');
ylabel('Y (pixels)');
zlabel('Intensity (double precision corrected) [a.u.]');
dlmwrite('test.csv', data, '-append') %write all values from
%intensity profile into a csv
%file
end
hold off

Risposte (1)

Brian Hannan
Brian Hannan il 1 Lug 2015
Modificato: Brian Hannan il 1 Lug 2015
Getting the subplot's handle will allow you to do this. Here's a simplified version of your code that plots to only one figure.
figure(1);
hs = subplot(2,1,1); % Get subplot handle here.
[xx,yy] = meshgrid(1:10, 1:10);
for p = 1:3
i = p.*(sin(xx)+cos(yy)); % Some dummy data for demonstration only.
mesh(hs, xx, yy, i); % Give mesh the suplot's axes handle here.
pause(1); % Stop for a second so we can see the animation.
end

4 Commenti

I tried getting the subplot's handle. When I do this an error message comes up saying that the data dimension don't agree. Here's the small section with the revised code. There's an error on the second to last line, mesh(hs,xx,yy,i).
if true
% code
end
%intensity plot info
[x,y] = size(sequence(:,:,p));
X = 1:x;
Y = 1:y;
[xx,yy] = meshgrid(Y,X); %intensity profile in 3-D space
hs = subplot(2,1,1); %get sublot handle
i = im2double(sequence(:,:,p)); %convert images to double precision
mesh(hs,xx,yy,i); %give mesh the subplot's axes handle
pause(1); %stop for a second to see animation
It's not possible for me to know what the error is without more context, but it sounds like there's a problem with the relative size between the 3rd dimension of sequence, xx and yy, and not caused by the code that generates the figure.
I checked to see that xx and yy and i are all compatible. They're all the same size (100x100 double). hs is 1x1 axes. I'm not sure if there's anything wrong with that.
xx and yy are necessarily the same size since they were produced by the same call to meshgrid. However, it sounds like your problem is coming from the matrix you called sequence, so I would start there.

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Richiesto:

il 1 Lug 2015

Modificato:

il 1 Lug 2015

Community Treasure Hunt

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

Start Hunting!

Translated by