簡體   English   中英

Matlab - 實時繪制 3D 圖形

[英]Matlab - Drawing 3D figure in real time

我正在嘗試繪制在 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

感謝燒杯,我設法通過將 figure 命令保持在循環之外來將幀保持在圖中。

我設法通過在圖形之后添加突擊隊集(gcf,'Visible','on')以在與實時編輯器不同的窗口中顯示它來自己解決另外兩個問題,並且我設法通過使用添加自定義顏色圖小寫字母而不是像在文件名 newColorCamp.mat 中那樣使用駝峰字母。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM