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:
save matrix as a struct

Subject: save matrix as a struct

From: Aidy

Date: 1 Jan, 2011 17:43:04

Message: 1 of 5

good day friends,


I have a 3x3 matrix A.

A =
         1 4 2
         9 8 5
         7 6 4

How I can convert this matrix into a 1x3 struct array with the same field name for all columns?

thanks
aiden

Subject: save matrix as a struct

From: Walter Roberson

Date: 1 Jan, 2011 17:52:15

Message: 2 of 5

On 01/01/11 11:43 AM, Aidy wrote:

> I have a 3x3 matrix A.
>
> A = 1 4 2
> 9 8 5
> 7 6 4
>
> How I can convert this matrix into a 1x3 struct array with the same
> field name for all columns?

I'm not clear as to whether you wish to convert along rows or columns.

foo = struct('bar', mat2cell(A, 3, ones(1,3))).'

The trailing .' is because it would normally create an N x 1 struct
array rather than a 1 x N struct array. Working with 1 x N struct arrays
is certainly possible, but it isn't often seen in practice.

Subject: save matrix as a struct

From: Aidy

Date: 1 Jan, 2011 18:08:05

Message: 3 of 5

thank you,
aiden

Subject: save matrix as a struct

From: Oleg Komarov

Date: 1 Jan, 2011 18:11:04

Message: 4 of 5

"Aidy" wrote in message <ifnp38$osn$1@fred.mathworks.com>...
> good day friends,
>
>
> I have a 3x3 matrix A.
>
> A =
> 1 4 2
> 9 8 5
> 7 6 4
>
> How I can convert this matrix into a 1x3 struct array with the same field name for all columns?
>
> thanks
> aiden

Why would you want to do that?

Oleg

Subject: save matrix as a struct

From: Aidy

Date: 1 Jan, 2011 19:56:04

Message: 5 of 5

a program I'm working with requires its input to be a struct.

--aiden

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