MATLAB: Save a three dimensional matrix

three dimensional matrix

How can i save a three dimensional matrix. The following does not work
for b=1:size(GP,3);
Q(:,:,b)=wtpt*GP(:,:,b);
save('G:\.........\Q.txt','Q','-ASCII','-double');
end
Thanks

Best Answer

Hi,
you have two options: one would be to save the individual slices
for b=1:size(GP, 3)
Q(:,:, b) = wtpt*GP(:,:,b);
A = Q(:,:,b);
save(sprintf('G:\Q_%d.txt', b), 'A', '-ASCII', '-double');
end
The alternative would be to use reshape to make it a 2D matrix, and when you load it, reshape it back to a 3D matrix. It depends what you need the ascii output for.
Titus