Pregunta

I have a 3D array representing an image in MATLAB. I want to reverse the position of pages(in my case slices). Let's assume the number of pages is N. I want to replace first page with Nth, second with (N-1)th and so on.. Is there any function to do it in matlab. Now I am using the code below, but I have to avoid nested for loops, that is why I am looking for a prepared function. Any help would be appreciated.

Thank you in advance

I = ones(size(Image,1),size(Image,2),size(Image,3));
k=1;
for n=size(Image,3):-1:1
    I(:,:,k) = Image(:,:,n);
    k = k+1;
end
¿Fue útil?

Solución

You can simply

I = Image(:,:,end:-1:1);

Otros consejos

Another possibility, which lets you use the same notation for flipping the array along any dimension:

I = flipdim(Image, 3); %// 3 is the dimension you want to flip along
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top