Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem with multi-dimensional array

Subject: Problem with multi-dimensional array

From: Santonu Goswami

Date: 8 Dec, 2010 19:33:05

Message: 1 of 7

Please bear with me, I am pretty new to Matlab and seeking help here from you all.
I am looking for some help with creating a multi-dimensional array. I am trying to create a A(x,y,n) array using n - numbers of An(x,y) arrays.
I am creating the 3-D array with
A = zeros(x,y,n)

and then trying to load the 2-D arrays one at a as follows:
A( :, :, 1) = A1(x,y)
A( :, :, 2) = A2(x,y)
etc.

Now when I save the 3D array and use 'whos' to see it in matlab space, I can see the size to be reflective as a total of all the 2D arrays.

But the problem is when I look at the file in my windows folder, I do not see the same size.
I am confused what is happening here and would appreciate any help.
Thanks in advance.

Subject: Problem with multi-dimensional array

From: Sean de

Date: 8 Dec, 2010 19:41:08

Message: 2 of 7

"Santonu Goswami" <santonu@gmail.com> wrote in message <idomhh$kav$1@fred.mathworks.com>...
> Please bear with me, I am pretty new to Matlab and seeking help here from you all.
> I am looking for some help with creating a multi-dimensional array. I am trying to create a A(x,y,n) array using n - numbers of An(x,y) arrays.
> I am creating the 3-D array with
> A = zeros(x,y,n)
>
> and then trying to load the 2-D arrays one at a as follows:
> A( :, :, 1) = A1(x,y)
> A( :, :, 2) = A2(x,y)
> etc.
>
> Now when I save the 3D array and use 'whos' to see it in matlab space, I can see the size to be reflective as a total of all the 2D arrays.
>
> But the problem is when I look at the file in my windows folder, I do not see the same size.
> I am confused what is happening here and would appreciate any help.
> Thanks in advance.

if A1,A2... An are full matrices then you're setting all rows and cols of the nth slice to one value (A1(x,y))

try
A(:,:,1) = A1;
A(:,:,2) = A2;... setting the whole A# matrix to be all rows+slices

Subject: Problem with multi-dimensional array

From: Walter Roberson

Date: 8 Dec, 2010 19:45:25

Message: 3 of 7

On 10-12-08 01:33 PM, Santonu Goswami wrote:
> Please bear with me, I am pretty new to Matlab and seeking help here
> from you all. I am looking for some help with creating a
> multi-dimensional array. I am trying to create a A(x,y,n) array using n
> - numbers of An(x,y) arrays. I am creating the 3-D array with A =
> zeros(x,y,n)
>
> and then trying to load the 2-D arrays one at a as follows:
> A( :, :, 1) = A1(x,y)
> A( :, :, 2) = A2(x,y)
> etc.
> Now when I save the 3D array and use 'whos' to see it in matlab space, I
> can see the size to be reflective as a total of all the 2D arrays.
> But the problem is when I look at the file in my windows folder, I do
> not see the same size. I am confused what is happening here and would
> appreciate any help. Thanks in advance.

If you are looking at the size of the .mat file, what you need to know is that
-v7 .mat files (the default) use data compression, and so are often smaller
than the data set being saved, sometimes *much* smaller.

Subject: Problem with multi-dimensional array

From: Santonu Goswami

Date: 8 Dec, 2010 20:13:07

Message: 4 of 7

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <idon0k$lo7$1@fred.mathworks.com>...

> if A1,A2... An are full matrices then you're setting all rows and cols of the nth slice to one value (A1(x,y))
>
> try
> A(:,:,1) = A1;
> A(:,:,2) = A2;... setting the whole A# matrix to be all rows+slices

A1, A2 all are full matrices of fixed size (601,300)....and n = 20
I guess what you are suggesting it repeat it for 20 times.

Subject: Problem with multi-dimensional array

From: Walter Roberson

Date: 8 Dec, 2010 20:15:22

Message: 5 of 7

On 10-12-08 02:13 PM, Santonu Goswami wrote:
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> <idon0k$lo7$1@fred.mathworks.com>...
>
>> if A1,A2... An are full matrices then you're setting all rows and cols
>> of the nth slice to one value (A1(x,y))
>>
>> try
>> A(:,:,1) = A1;
>> A(:,:,2) = A2;... setting the whole A# matrix to be all rows+slices
>
> A1, A2 all are full matrices of fixed size (601,300)....and n = 20
> I guess what you are suggesting it repeat it for 20 times.

http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

Subject: Problem with multi-dimensional array

From: Santonu Goswami

Date: 8 Dec, 2010 20:17:06

Message: 6 of 7

Walter Roberson <roberson@hushmail.com> wrote in message <idon8m$d3n$2@canopus.cc.umanitoba.ca>...

> If you are looking at the size of the .mat file, what you need to know is that
> -v7 .mat files (the default) use data compression, and so are often smaller
> than the data set being saved, sometimes *much* smaller.

Walter thanks for your reply. It seems to be way to compressed to me and instead of seeing about 30MB, I can see the size of abt 200KB.
I just tried

Save A

after I added all the layers and then I can see the size of the file in the windows folder to be similar to what I think it should be. But then again when I convert it to ENVI readable file and load it to ENVI as an image, I see very different numbers.

Subject: Problem with multi-dimensional array

From: James Tursa

Date: 8 Dec, 2010 21:12:07

Message: 7 of 7

"Santonu Goswami" <santonu@gmail.com> wrote in message <idop42$b6q$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <idon8m$d3n$2@canopus.cc.umanitoba.ca>...
>
> > If you are looking at the size of the .mat file, what you need to know is that
> > -v7 .mat files (the default) use data compression, and so are often smaller
> > than the data set being saved, sometimes *much* smaller.
>
> Walter thanks for your reply. It seems to be way to compressed to me and instead of seeing about 30MB, I can see the size of abt 200KB.
> I just tried
>
> Save A
>
> after I added all the layers and then I can see the size of the file in the windows folder to be similar to what I think it should be. But then again when I convert it to ENVI readable file and load it to ENVI as an image, I see very different numbers.

It may be best to show us the actual code & steps you are taking. i.e., show us the exact m-code you are using to build/save/load the data. And show us the actual file size etc you are seeing. etc.

James Tursa

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us