0

I'm reading binary data from a file, the particular value in question is a uchar (unsigned 1-byte value) and conceptually is boolean. How do I write the fread statement?

I.e. what should I put in for ??? in the following:

is_valid=fread(fid, 1, 'uint8=>???','a');

I figure that I could use '*uint8' for the conversion string, but I'd like for the result type to be most-like what other users would expect.

2 Answers 2

2

Booleans in MATLAB are represented by the logical type. However, fread doesn't support reading logicals, so read them as uint8 and convert to logical later. For instance:

is_valid = logical(fread(fid, 1, 'uint8', 'a'));
Sign up to request clarification or add additional context in comments.

Comments

0

This works on 2012b:

A = fread(fid, 1, 'uint8=>logical');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.