Basic MATLAB Functions
1) Assigning number to variable:
We use = (Equal) sign to assign number to variable and end the line with semicolon.
2) Check the Class or Datatype:
Using Class Function:
We use class (your input) function to check the datatype or class of the input. As you can see in the image below.
Using whos Function:
To get detail information about the input data, we use the function whos('your data').
3) Assigning signed integer to variable:
To assign the variable an integer (signed) value we use int64(your data). As you can see in the image below.
4) Assigning unsigned integer to variable:
To assign the variable an unsigned integer value we use uint64(your data).
As you can see in the image below.
5) Changing the Format:
Short format:
Short, fixed-decimal format with 4 digits after the decimal point. This is the default numeric setting.
Long, fixed-decimal format with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values.
bank format:
Currency format with 2 digits after the decimal point.
Rational format:
Ratio of small integers.
Hexadecimal format:
Hexadecimal representation of a binary double-precision number.
We can assign the string to variable; we just need to use single quotes.
What if our string has single comma already then, no worries just add to two single commas as you can see in screenshot.
Adding two or more strings is concatenation. We use square brackets for concatenation of strings separated by spaces.
8) Add number to String:
We can add number to the string by using num2str() function.
9) Print Function:
When we code in script, it does not print out every line. In order to show the results on command line, we use disp() function for this purpose.
We can compare the strings too. It is case insensitive meaning small and big letters will be treated same. The answer will be binary meaning 0 for False and 1 for True.
Using Script instead of Command Window:
To use the script instead of command window you need to make end each line with semicolon. To display the answer, you need to use disp function. You also need to run the code every time by clicking the green play button.What is Matlab? How to download it free Click here
If you have any queries do let me know in comments. If not, you can say hi too. I love it 🙂.
0 Comments