Using slice in a fuction and from command window
Show older comments
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 Comments
Selva Karna
on 17 Aug 2017
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
on 17 Aug 2017
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!