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

New to MATLAB?

fread order of operations

Asked by Jim Hokanson

Jim Hokanson (view profile)

on 18 Mar 2011

Does Matlab enforce some sort of order of executions for fread statements?

For example, if we did: fread(fid,1,'int8')*3 + fread(fid,1,'uint8')*4

Would the 'int8' read always execute before the 'uint8'?

I would have no reason to expect this, and it seems like either this should be the case, or this should show an mlint warning.


Jim Hokanson

Jim Hokanson (view profile)


No products are associated with this question.

1 Answer

Answer by Jan Simon

Jan Simon (view profile)

on 18 Mar 2011
Accepted answer

In the documentation I find:

Operator precedence ... Within each precedence level, operators have equal precedence and are evaluated from left to right.

This means, that the left FREAD is performed at first ever.


Walter Roberson

Walter Roberson (view profile)

on 18 Mar 2011

Though I wonder if this is strictly followed with JIT ?

Jan Simon

Jan Simon (view profile)

on 19 Mar 2011

The execution order is a very fundamental and documented behaviour. Of course it is possible, that the JIT has such a serious bug. But I do not find a corresponding bug report.

What about: a(fread(fid, 1, 'uint8')) = fread(fid, 1, 'uint16')
The UINT16 is read at first, but I can anyone find a corresponding statement in the documentation.

Jan Simon

Jan Simon (view profile)

Contact us