Using slice in a fuction and from command window
显示 更早的评论
Hi everyone: I am using slice to display views of a Ultrasound created image volume. When I run it from the comman window I get the error of "Index exceeds matrix dimensions" but if I create a function in which I call slice and produce the cuts then it works. I have tried with simple examples like the one included in the description of the slice function usage and I get the same results. Being a the volume with dimensions (149x148x200):
-------------------------------------------
Command Window: sizevol=size(a);
% %slice and visualise cross sections for volume
[xgrid,ygrid,zgrid]=meshgrid(1:sizevol(2),1:sizevol(1),1:sizevol(3));
a=double(a);
h=slice(xgrid,ygrid,zgrid,a,100,100,10);
ERROR - Index exceeds matrix dimensions
-------------------------------------------
Function: slicefcn(a);
"""""
function slicefnc(V)
figure;
[x,y,z] = meshgrid(1:size(V,2),1:size(V,1),1:size(V,3));
hslices=slice(x,y,z,V,size(V,2)/2,size(V,1)/2,size(V,3)/2);%
colormap(gray);
xlabel('x');ylabel('y');zlabel('z');
end
""""
getting the desired result attached;
Has anyone an idea why this happens? am I missing or ignoring something? Cheers
Sergiusz
2 个评论
Selva Karna
2017-8-17
V1=magic(5); V(:,:,1)=V1 V(:,:,2)=V1 V(:,:,3)=V1 slicefnc(V)
function slicefnc(V) figure; [x,y,z] = meshgrid(1:size(V,2),1:size(V,1),1:size(V,3)); hslices=slice(x,y,z,V,size(V,2)/2,size(V,1)/2,size(V,3)/2);% colormap(gray); xlabel('x');ylabel('y');zlabel('z'); end

Sergio Morales
2017-8-17
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!