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:
Reading a binary C array in Matlab (reordering elements...)

Subject: Reading a binary C array in Matlab (reordering elements...)

From: Luca

Date: 12 Mar, 2013 15:52:05

Message: 1 of 2

Hello everybody!

I am given some binary files written in C, which contain a float array F[30][4][2].
If I read them in Matlab using fread
F = fread (fid,30*4*2,'float');

I cannot get in any way my original vector F with the elements in the correct order.
It doesn't matter the combinations of reshape/permute/transpose I use...
I know this should be an extremely easy task to pass from row-ordering to column ordering, but I've lost myself and can't get anywhere working with 3 dimensions and not 2!!
Can anybody give me some clues?

Thank you very much!

Subject: Reading a binary C array in Matlab (reordering elements...)

From: Luca

Date: 12 Mar, 2013 17:28:05

Message: 2 of 2

"Luca " <l.presottoRE@MOVE.campus.unimib.NOTit> wrote in message !
> Can anybody give me some clues?
>
> Thank you very much!

Got it!
I write it here for the records, in case somebody gets stuck on google for hourse like I did. :-D :-D

It's just
If in C I had:
float Data[nx][ny][nz];

In matlab I should do:

data = reshape (data,nz,ny,nx);
data = permute (data,[3 2 1]);

Pretty obvious indeed....

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