MATLAB
MATLAB
1 2 3
4 5 6
Here A11 = 1 , A12 = 2 , A13 = 3. A21 = 4, A22 = 5 and A23 = 6.
Q. 3 Rational and logical operation of matlab.
Ans. MATLAB has rational and logical operators that can be used to
compare values and determine what to do next:
Rational operators
These include addition, subtraction, multiplication, division, and
exponentiation. All rational operations are done on entire arrays,
using matrix definitions.
Logical operators
These return a logical array with elements set to true (1) or false
(0). Some examples of logical operators include:
&: Logical AND
| Logical OR
~A: Complements the elements of A
xor(A,B): Implements the exclusive OR operation
Relational operators
These are used to compare values of different variables. Some
examples of relational operators include:
<: Less than
<= Less than equal to
>: Greater than
>= Greater than or equal to
== Equal to
~=`: Not equal to
You can use the Logical Operator block from the Logic and Bit
Operations library to include a logical operation in your model. You
can also replace the Logical Operator block with a Relational
Operator block
Q. 4 Creating a plot using plot function in matlab
Ans. - Create a simple line plot and label the axes. Customize the
appearance of plotted lines by changing the line color, the line style,
and adding markers.
Create Line Plot
Create a two-dimensional line plot using the plot function. For
example, plot the value of the sine function from 0 to 2π.
Get
x = linspace(0,2*pi,100);
y = sin(x);
plot(x,y)
Label the axes and add a title.
Get
xlabel('x')
ylabel('sin(x)')
title('Plot of the Sine Function')
Q. 5 Complex and stastical function .
Ans. - Syntax
z = complex(a,b)
z = complex(x)
Description
z = complex(a,b) creates a complex output, z, from two real inputs,
such that z = a + bi.
The complex function provides a useful substitute for expressions,
such as a + 1i*b or a + 1j*b, when
a and b are not double or single
b is all zeros
example
z = complex(x) returns the complex equivalent of x, such
that isreal(z) returns logical 0 (false).
If x is real, then z is x + 0i.
If x is complex, then z is identical to x.
example
Examples
collapse all
Complex Scalar from Two Real Scalars
Open in MATLAB OnlineCopy Code Copy Command
Use the complex function to create the complex scalar, 3 + 4i.
Get
z = complex(3,4)
z=
3.0000 + 4.0000i
Complex Vector from Two Real Vectors
Open in MATLAB OnlineCopy Code Copy Command
Create a complex uint8 vector from two real uint8 vectors. The size
of z, 4-by-1, is the same as the size of the input arguments.
Get
a = uint8([1;2;3;4]);
b = uint8([2;2;7;7]);
z = complex(a,b)
z = 4x1 uint8 column vector
1 + 2i
2 + 2i
3 + 7i
4 + 7i
Categorical Arrays
Arrays of qualitative data with values from a finite set of
discrete, nonnumeric data
Tables
Arrays in tabular form whose named columns can have different
types
Timetables
Time-stamped data in tabular form
Structures
Arrays with named fields that can contain data of varying types
and sizes
Cell Arrays
Arrays that can contain data of varying types and sizes
Function Handles
Variables that allow you to invoke a function indirectly
Dictionaries
Map data with keys that index values
Time Series
Data vectors sampled over time
%Number Matrix
x = [1 2 3;4 5 6;7 8 9]
%String Matrix
y = ['Geeks';'Geeks']
Output:
MATLAB
% Creating matrices
x = [1 2 3 4;4 5 6 7;7 8 9 10];
xSize = size(x)
y=['Geeks';'Geeks'];
ySize = size(y)
Output:
Example 1:
MATLAB
% Creating matrices
x = [1 2 3 4;4 5 6 7;7 8 9 10];
x(3,2)
y=['Geeks';'Geeks'];
y(1,2)
Output:
matrix(x:y;,xy)