我有一个尺寸为2001,2001,30的3D大矩阵。我想在3D图中显示它的30个切片。我尝试使用matlab'slice'命令。但是,由于'slice'需要从'meshgrid'命令将X Y Z位置作为3D数组,我得到'内存不足错误'。
我的代码如下所示。
如何在不缩小的情况下克服“Out of Memory”错误 我的3D矩阵,并使用矩阵数据的x,y,z位置
function presentFig4_ver4
close all; clc;
%im3 is of size of im3 = 201 201 30
load('img3D_shrinked.mat' , 'im3' , 'y_n_mm' , 'x_n_mm')
% next code until the mesh grid is in order to have the axes arranged
% so that the slices are shown one after the other in the depth
% direction of the figure and not from the bottom of the figure to the top of the figure
x_len=length(x_n_mm);
y_len=length(y_n_mm);
im3_reshaped=zeros(y_len , x_len , y_len);
for (ind_slice=1:30)
im3_reshaped(:,ind_slice,:)=im3(:,:,ind_slice);
end
[X,Y,Z]=meshgrid(x_n_mm,y_n_mm,y_n_mm);
slices=x_n_mm %= 0.23:0.1:(0.23+((30-1)*0.1)); %This is the same as x_n_mm
shownSlices=[1:30];
h=slice(X,Y,Z, im3_reshaped, [slices(shownSlices)],[],[]);
set(h,'EdgeColor','none','FaceColor','interp');
set( h , 'FaceAlpha', 'interp','AlphaData',im3*10^3)
dcm_obj = datacursormode(gcf); %datacursor mode on
set(dcm_obj,'enable','on','updatefcn',{@updateMe X Y Z im3_reshaped}) %update, need X,Y,Z, im3-values
set(gca,'FontName', 'Arial' ,'FontSize',14)
set(gca,'Position',[.32 .19 .41 0.9]) % [horizontal distance, vertical distance, width, height]
hold on
%camproj perspective
c_h=colorbar('horiz');
set( c_h, 'XDir', 'reverse' , 'Position' , [0.2 0.2 0.7 0.04],'FontSize',12);
opengl software
daspect([ 1 10 10])
axis tight
view(-49,16)
maxAxisLim=2; %mm
ylim([-maxAxisLim maxAxisLim])
zlim([-maxAxisLim maxAxisLim])
xlim([0.23 3.13])
camzoom(2)
xlabel('X [mm]','FontName', 'Arial' , 'FontSize',14)
ylabel('Y[mm]','FontName', 'Arial' ,'FontSize',14)
zlabel('Z [mm]','FontName', 'Arial' , 'FontSize',14)
x_h=get(gca,'XLabel');
y_h=get(gca,'YLabel');
z_h=get(gca,'ZLabel');
set(y_h, 'Units','normalized','Position', [0.03 -0.08 ] );
set(x_h, 'Units','normalized','Position', [0.6 0.12] );
set(z_h, 'Units','normalized','Position', [-0.08 0.27] );
set(get(gca,'YLabel'),'Rotation',-20);
set(get(gca,'XLabel'),'Rotation',12);
set(gca,'XTick',[0.23 0.5:0.5:3 3.13])
set(gca,'XTickLabel',{'0.23' '0.5' '1' '1.5' '2' '2.5' '3' '3.1' })
end % of presentFig4_ver4 function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function msg = updateMe(src,evt,X,Y,Z,f)
evt = get(evt); %what's happenin'?
pos = evt.Position; %position
fval = f(X==pos(1)&Y==pos(2)&Z==pos(3)); %where?
msg = num2str(fval); %create msg
end