How to update 3-D plot after every loop?

조회 수: 14 (최근 30일)
Jessica Flores
Jessica Flores 2015년 7월 1일
편집: Brian Hannan 2015년 7월 1일
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

답변 (1개)

Brian Hannan
Brian Hannan 2015년 7월 1일
편집: Brian Hannan 2015년 7월 1일
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
Jessica Flores
Jessica Flores 2015년 7월 1일
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.
Brian Hannan
Brian Hannan 2015년 7월 1일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by