0% found this document useful (0 votes)
15 views5 pages

Programming Assignment222

Uploaded by

haydayuser4599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

Programming Assignment222

Uploaded by

haydayuser4599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Matlab commands and their definations, syntax and examples

1. clc
- Definition Clears the Command Window.

- Syntax `clc`

- Example: Clears the Command Window to provide a clean slate.

2. clear all:
- Syntax `clear all`

- Example Removes all variables and their values from the workspace.

3. close all:
- Definition: Closes all open figure windows.

- Syntax: `close all`

- Example: Closes all currently open plot windows.

4.Commenting:
-Definition: This symbol is used to comment

- Example`% Calculate the sum`

5. Semi colon (;):


- Definition: Suppresses output in the Command Window.

- Syntax: `x = 5;`

- Example: `result = a + b;`

6. Num2int:
- Definition: Converts numbers to integers.

- Syntax: `num2int(x)`

- Example: `num = 3.14; intNum = num2int(num);`


7. Disp:
- Definition: Displays output in the Command Window.

- Syntax: `disp('Hello, MATLAB!')`

- Example: `disp('Result is:'); disp(result);`

8. ...:
- Definition: Continuation to the next line in MATLAB.

- Syntax: `A = [1 2 3; ... 4 5 6]`

- Example: Creates a matrix `A` with two rows.

9. input:
- Definition: Takes user input.

- Syntax: `x = input('Enter a value: ')`

- Example: `radius = input('Enter the radius: ');`

10. Assigning Variables:


- Definition: Storing values in variables.

- Syntax: `variable = value`

- Example: `height = 10;`

11. Defining Matrices:


- Row Matrix: `A = [1 2 3]`

- Column Matrix: `B = [4; 5; 6]`

- Colon Operator: `C = 1:5`

12Linspace:
- Definition: Generates linearly spaced vectors.

- Syntax: `linspace(start, end, n)`

- Example: `x = linspace(0, 1, 100);`


13. Zeros, Ones, Eye:
- Syntax: `zeros(m, n)`, `ones(m, n)`, `eye(n)`

- Example: `A = zeros(3, 3); B = ones(2, 2); C = eye(4);`

14. Rand, randi, randn:


- Syntax: `rand(m, n)`, `randi([min, max], m, n)`, `randn(m, n)`

- Example: `A = rand(2, 3); B = randi([1, 10], 3, 2); C = randn(4, 4);`

15. Size, Max, Min:


- Syntax: `size(A)`, `max(A)`, `min(A)`

- Example: `sz = size(A); maxValue = max(A); minValue = min(A);`

16. Magic:
- Definition: Creates a magic square.

- Syntax: `magic(n)`

- Example: `M = magic(3);`

17. Sum, Mean, Prod, Numel:


- Syntax: `sum(A)`, `mean(A)`, `prod(A)`, `numel(A)`

- Example: `total = sum(A); avg = mean(A); product = prod(A); count = numel(A)

18. If, For, While, Switch:


- Syntax: if condition, end`, `for i = 1:n, end`, `while condition, end`, `switch case, end`

- Example:

matlab

if x > 0

disp('Positive');

else

disp('Non-positive');
end

```

19. Format, Round, Ceil, Floor, Fix:


- Syntax: `format`, `round(x)`, `ceil(x)`, `floor(x)`, `fix(x)`

- Example: `format short; rounded = round(3.14);`

20. Table:
- Definition: Creates a table.

- Syntax: `T = table(column1, column2, ...);`

- Example: `T = table(names, ages, heights);`

21. Length:
- Definition: Returns the length of a vector or matrix.

- Syntax: `length(A)`

- Example: `vecLength = length(A);`

22. Functions:
- Definition: Reusable blocks of code.

- Syntax:

```matlab

function output = functionName(input)

% Code here

output = processedInput;

end

```

- Example:

```matlab

function result = addTwoNumbers(a, b)

result = a + b;
end

You might also like