Ajay Ganti
Ajay Ganti

Reputation: 35

How to process a large matrix of size 28x28x11684?

I'm having 11684 matrices each of size 28x28. So the variable a has size 28x28x11684. Now i would like to do sorting them using a for loop on each matrix of 28x28 and store it in a variable z. Here is my code

for i=1:11684
    z=sort(a(:,:,i));
end

When i run the code, it is giving me the variable z of size 28x28. But i want the variable z to be of size 28x28x11684. Plese help me.

Upvotes: 0

Views: 55

Answers (2)

Sardar Usama
Sardar Usama

Reputation: 19689

You don't need any loop at all. sort is directly applicable on multi-dimensional arrays as well.

z = sort(a);   

This is it!

Upvotes: 1

Mendi Barel
Mendi Barel

Reputation: 3677

Remember that sort will sort the columns. This is how you do it:

a=rand(28,28,55);
z=a*0;
for i=1:size(a,3)
    z(:,:,i)=sort(a(:,:,i));
end

Upvotes: 0

Related Questions