Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Built-in Functions in MATLAB: A Comprehensive List, Study Guides, Projects, Research of Matlab skills

A list of essential built-in functions in MATLAB, including their syntax and examples. Functions covered are square root, remainder, length, size, absolute value, any root, sign, summation, product, cumulative summation and product, average, ascending and descending sorting, nearest integer, truncation, maximum, minimum, factorial, exp, log, and log10. Each function is explained with an example.

What you will learn

  • What is the syntax for calculating the square root of a number in MATLAB?
  • What is the function to find the number of rows and columns in a matrix in MATLAB?
  • How do you find the remainder of dividing two numbers in MATLAB?

Typology: Study Guides, Projects, Research

2021/2022

Uploaded on 09/12/2022

anoushka
anoushka 🇺🇸

4.1

(15)

241 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
11
Some important Built-in function in MATLAB
1.
Square root
b=sqrt(x)
b=sqrt(4)
2
2.
Remainder of dividing x/y
a=rem(x,y)
a=rem(10,3)
1
3.
Number of 1D arrayed
n=length(d)
d=[3 2 -1 7]
Length(d)
4
4.
Number of rows & columns of a 2D array
[row,cols]=size(d)
F=size(d)
d=[1 2 3;4 5 6]
F=size(d)
2 3
5.
Absolute value
abs(x)
6.
Any root of x
nthroot(x,n)
nthroot(8,3)
2
7.
The sign of x
sign(x)
-1 or 1
8.
Summation
sum(x)
x=[1,5,3];
y=[1,5,3;2,4,6];
disp(sum(x))
disp(sum(y))
9
3 9 9
9.
Product
prod(x)
prod([1 5 3])
15
prod(y)
2 20 18
10.
Cumulative
Summation
cumsum(x)
x=[2 4 5;
2 5 4;
4 5 6]
cumsum(x)
2 6 11
2 7 11
4 9 15
11.
Cumulative
Product
cumprod(x)
يمكارتلا عمجلا ةيلمع سفنل
برضلا لمعن هلاعا
12.
Average
mean(x)
x=[1 5 3];
mean(x)
3
y=[1 2 3;4 5 6];
mean(y)
2.5 3.5 4.5
13.
Ascending sorting
sort(x)
لك ىلع قبطي يدعاصت
دومع
pf3
pf4
pf5

Partial preview of the text

Download Built-in Functions in MATLAB: A Comprehensive List and more Study Guides, Projects, Research Matlab skills in PDF only on Docsity!

Some important Built-in function in MATLAB

  1. Square root b=sqrt(x) b=sqrt(4) 2
  2. Remainder of dividing x/y a=rem(x,y) a=rem(10,3) 1
  3. Number of 1D arrayed n=length(d) d=[3 2 - 1 7] Length(d) 4
  4. Number of rows & columns of a 2D array [row,cols]=size(d) F=size(d)

d=[1 2 3;4 5 6] F=size(d) 2 3

  1. Absolute value abs(x)
  2. Any root of x nthroot(x,n) nthroot(8,3) 2
  3. The sign of x sign(x) - 1 or 1
  4. Summation sum(x) x=[1,5,3]; y=[1,5,3;2,4,6]; disp(sum(x)) disp(sum(y)) 9 3 9 9
  5. Product prod(x) prod([1 5 3]) 15 prod(y) 2 20 18
  6. Cumulative Summation

cumsum(x) x=[2 4 5; 2 5 4; 4 5 6] cumsum(x) 2 6 11 2 7 11 4 9 15

  1. Cumulative Product

cumprod(x) لنفس عملية الجمع التراكمي اعاله نعمل الضرب

  1. Average mean(x) x=[1 5 3]; mean(x) 3 y=[1 2 3;4 5 6]; mean(y) 2.5 3.5 4.
  2. Ascending sorting sort(x) تصاعدي يطبق على كل عمود
  1. Descending sorting sort(x,'descend') يطبق على كل عمود تنازلي
  2. sortrows(x) الفرز على اساس العمود االول تصاعدي
  3. sortrows(x,n) الفرز على اساس العمود المختار فقط تصاعدي
  4. nearest integer round(x) round(8.6) ans=
  5. Truncation fix(x) fix(8.6) fix(-8.6) ans=8 ans=- 8
  6. Towards the lesser floor(x) floor(-8.6) ans=- 9
  7. Towards the greater ceil(x) ceil(-8.6) ans=- 8
  8. Maximum max(x) [a,b]=max(x) max(x,y)

x=[1 5 3] max(x) ans= x=[1 5 3;2 4 6] max(x) ans= 2 5 6 x=[1 5 3] [a,b]=max(x) a=5 value b=2index x=[1 5 3;2 4 6] y=[10 2 4;1 8 7] max(x,y) ans= 10 5 4 2 8 7

  1. Minimum min(x) [a,b]=min(x) min(x,y)
  2. factorial(x) 5!=54321 factorial(5) ans=
  3. exp(x)
  4. log(x)
  5. log10(x)

Ex6) write MATLAB program to print a table of 3 columns, where column 1 is the angles from 0 to 2π at a step of π/4, the second column is given by y=2(sin(x)+cos(x)) and the third column is the nearest integer of y.

disp & fprintf x=1:5; disp(‘the values are’) disp(x) عند التنفيذ يظهر على الشاشة The value are 1 2 3 4 5 لغرض اظهار الناتج بنفس الخط نستخدم امر الطبع ادناه disp([‘the values are,’num2str(x)]) the values are 1 2 3 4 5 num2str: to transfer the x matrix to character array. fprintf: formatted print function ex: feet=1: Inches=feet.*12; table=[feet;inches]; fprintf(‘%4.0 %7.2\n’,table) 1 12. 2 24. 3 36. %7. 7=no. of digit, 2= no. of decimal , \n =new line Ex9) you have weather data of 4 weeks of daily average temperatures (28values). Write matlab code to find and print the maximum, minimum and average temperature in each week. clear,clc t1=[20 21 24 22 25 21 23;… 21 21.5 28 23 25 22 23;… 25 24 24 23.2 25.5 23 26;… 22 21 29 27 25 23 22]; t=t1'; ma=max(t); mi=min(t); avg=mean(t); %disp(t)

%disp('----------------------------') %disp(ma) %disp(mi) %disp(avg) fprintf(%5.2f %5.2f %5.2f %5.2f\n',t1) frintf('---------------------------------------\n') r=[ma;mi;avg]; fprintf(%5.2f %5.2f %5.2f %5.2f\n',r) frintf('---------------------------------------\n') fprintf(%5.2f %5.2f %5.2f %5.2f\n',ma) fprintf(%5.2f %5.f2 %5.2f %5.2f\n',mi) fprintf(%5.2f %5.2f %5.2f %5.2f\n',avg)

Logical functions and control structures Sequence Programming structures Selection Repetition Relation operators < less than <= less than or equal to

Greater than = greater than or equal to == equal to ~= not equal to

x=5; y=1; ans= x<y 0 x=1:5; y=x-4; ans= x<y 0 0 0 0 0 x=[1 2 3 4 5]; y=[-2 0 2 4 6]; ans= x<y 0 0 0 0 1 Logical operator & and x=[0 2 3 4 0]; ~ not y=[-2 0 2 4 0];