我试图在Matlab中绘制一个实时更新的3D圆柱体,它应该随着循环的值增加而交换帧(图像)。然而,我的问题是,它不是保持图形内的帧,而是为每个帧打开一个新的图形。
我不能使用我已经加载的自定义颜色图(这就是为什么我现在使用parula),我遇到的另一个问题是,我无法在实时编辑器中打开数字,我必须使用命令窗口。不知道是否有人会看到我在这里错过了什么,提前感谢!
我的代码。
clc;
clear all;
close all;
filename = ['*The file pathway*' 'filenames.txt'];
T = readtable(filename);
tsize = size(T);
tsize (1);
filename = strcat('*The file pathway*', string(T{350,1}));
heat = double(getHeatMap(filename));
load('newColorMap.mat');
for i = 1:tsize
filename = strcat('*The file pathway*', string(T{i,1}));
heat = double(getHeatMap(filename));
[X,tY] = meshgrid( linspace(1,400,size(heat,2)),linspace(0,2*pi,size(heat,1)));
max_heat = max(heat, [], 'all');
min_heat = min(heat, [], 'all');
R = (((heat-min_heat)/(max_heat-min_heat))*50)+100;
Y = cos(tY) .* R;
Z = sin(tY) .* R;
[nx, ny, nz] = surfnorm(X,Y,Z);
nv = reshape([nx ny nz], size(nx,1),size(nx,2),3);
CV = R;
figure
s = surf(X,Y,Z,heat,'VertexNormals',nv, 'EdgeColor','none');
axis([0 400 -200 200 -200 200])
colorbar
colormap('parula')
lighting gouraud
camlight
material dull
caxis([0 80])
drawnow
end
function heat = getCylinderHeatMap(filename)
%Returns a struct with info about the file.
s = dir(filename);
%Opens a file for reading, hence the 'r'.
fin = fopen(filename,'r');
I=fread(fin,s.bytes,'uint8=>uint8');
w = uint16(I(1))+256*uint16(I(2));
h = uint16(I(3))+256*uint16(I(4));
skip = s.bytes - w*h + 1;
IN = I(skip:1:s.bytes);
Z=single(reshape(IN,w,h));
Z=griddedInterpolant(Z');
y_range = linspace(1.0,single(h),360);
x_range = linspace(1.0,single(w),512);
heat = uint8(Z({y_range, x_range}));
end
多亏了beaker,我通过将figure命令保持在循环之外,成功地将框架保持在figure内。
我设法解决了另外两个问题,我自己通过添加突击队集(gcf,'可见','on')后,从实时编辑器显示它在一个单独的窗口,我设法添加自定义的颜色地图使用小写字母,而不是使用骆驼大小写,如在文件名newColorCamp.mat.