What is the difference between in64, int32, and int8. Are there anymore 'int' functions? (int means integer right?)

107 views (last 30 days)
So I am a beginner, like real beginner at MATLAB. I have a few questions
  1. Difference between %d, %f, or any other %?
  2. What does '%' represent?
  3. What is the difference between in64, int32, and int8. Are there anymore 'int' functions? (int means integer right?)
Please explain it as simple as possible. Thank you very much.

Accepted Answer

Peter O
Peter O on 1 Nov 2020
Difference between %d, %f, or any other %?
These are formatting control codes. %d prints a number in decimal (base 10) format, useful for integers. %f is for floating point (numbers with parts after the decimal point). See this article for an overview: https://www.mathworks.com/help/matlab/matlab_prog/formatting-strings.html
What does '%' represent?
Depending on the context, it's either a comment character or a formatting control character.
% Starting a line with a percent symbol means that it's a comment.
% The parser won't try to execute code or text behind it.
a = sin(pi); % You can also add them after an expression on the same line.
% For formatting control, you'll see it appear in a function like this, inside a string:
fprintf('Pi is: %5.2f.',pi);
What is the difference between in64, int32, and int8. Are there anymore 'int' functions? (int means integer right?)
Yes, int means integer. The number after it determines how many bits are used to hold the number, which determines the maximum size number it can hold. For instance an int8 has 8 bits of storage space and can hold 256 values (2^8). A 32-bit bit int holds a little bit over 4 billion values. MATLAB uses up to 64-bit precision, available in doubling amounts, so int8, int16, int32, and int64.
There are signed integers (intX) and unsigned integers (uintX). Unsigned will hold that range as all positive values and zero, while signed values will split the range between positive and negative numbers. For the 8-bit types, unsigned range is 0-255, while the signed int will range between -128 and + 127 (256 values, when you include zero).

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!