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:
Row or column operations?

Subject: Row or column operations?

From: Spencer

Date: 2 May, 2009 10:55:04

Message: 1 of 2

Hi,

When I have a large 2d matrix where one dimension is much larger than the other i.e for example 2x1000 is it better to store it as a 2x1000 or as a 1000x2 matrix? I heard somewhere that there is some natural way of storing stuff which corresponds to how MATLAB stores things in memory.

Any ideas?

/Spencer

Subject: Row or column operations?

From: Bruno Luong

Date: 2 May, 2009 11:12:01

Message: 2 of 2

"Spencer " <spencer.bastani@nek.uu.se> wrote in message <gth8q8$k3v$1@fred.mathworks.com>...
> Hi,
>
> When I have a large 2d matrix where one dimension is much larger than the other i.e for example 2x1000 is it better to store it as a 2x1000 or as a 1000x2 matrix? I heard somewhere that there is some natural way of storing stuff which corresponds to how MATLAB stores things in memory.
>

It depends what you do with your matrix. Matlab stores matrix in memory column wise. Thus the right thing to do is to store array so as access is more often on individual column. Another thing is to anticipate what some build-in functions that you might use and avoid to transpose your matrix. For example SORTROWS, UNIQUE with 'ROWS' option. Many functions work down naturally in the column (first dimension), such as MAX, MIN, INTERP1, etc...

Bruno

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