How to update 3-D plot after every loop?
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Brian Hannan
on 1 Jul 2015
Edited: Brian Hannan
on 1 Jul 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 Comments
Brian Hannan
on 1 Jul 2015
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.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!