0% found this document useful (0 votes)
9 views3 pages

Theory Assignments Module 1&2

MATLAB ASSIGMENTS

Uploaded by

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

Theory Assignments Module 1&2

MATLAB ASSIGMENTS

Uploaded by

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

Theory Assignments Module 1 & 2

Group A.
1.How do you start MATLAB, and what are the basic components of its user interface?
Ans – MATLAB can be started from from the MATWORKS website. After opening the website we
have to click Get MATLAB option, the after logging in we can get the interface of it.

Basic components of its user interface are Command Window, Workspace, Current Folder,
Command History, Editor, Figure Window, Toolstrip, Status Bar, Help Browser.

2. Describe the process to quit MATLAB.

Ans- We can type quit in that window, like this, >> quit and hit Enter.

3. What are the predefined variables in MATLAB? Give examples.

Ans- MATLAB has several predefined variables that are automatically available when we start a
session. For examples – ‘ans’ ‘pi’ ‘realmax’.

4. Define the term "vector" in the context of MATLAB.

Ans- A "vector" is a one-dimensional array that can hold a sequence of numbers. It can be either
a row vector (1xN) or a column vector (Nx1), where N is the number of elements. Vectors are
fundamental data structures in MATLAB used for storing and manipulating data.

5. How is a matrix different from an array in MATLAB?

Ans- A matrix is a two-dimensional array with rows and columns, specifically used for linear
algebra operations. An array, on the other hand, is a more general data structure that can have
multiple dimensions (e.g., 1D, 2D, 3D, etc.) and is used for storing data of any size or shape.

6. What is the use of the colon operator (:) in MATLAB?

Ans- The colon operator (:) in MATLAB is used to create vectors, specify ranges, and select
elements in arrays or matrices.

7. Describe how to access the elements of a vector in MATLAB.

Ans- To access elements of a vector in MATLAB, we use parentheses () with the index of the
element.
8. What is the significance of built-in functions in MATLAB? Give examples.

Ans- Built-in functions in MATLAB are pre-defined, optimized functions that simplify complex
computations and enhance productivity. They cover a wide range of tasks, including
mathematical operations, data analysis, and visualization. Eg – ‘sum()’ ‘mean()’ ‘plot()’.

9. How does MATLAB handle strings?

Ans- MATLAB handles strings as arrays of characters, which can be created using double quotes
(" "). MATLAB supports string manipulation through various functions like strcat() for
concatenation, strfind() for searching, and length() for finding the length of a string.

10.Describe the purpose of the size function in MATLAB.

Ans- The size function in MATLAB returns the dimensions of an array or matrix. It provides the
number of rows and columns for 2D arrays or the size of each dimension for higher-dimensional
arrays.

Group B.

1. Explain the use of the linspace and logspace functions in MATLAB.

Ans- Linspace: This function generates a linearly spaced vector. It creates a vector with a
specified number of points between two given values. It is particularly useful when you need to
create a range of values with equal spacing.

Logspace: This function generates a logarithmically spaced vector. It creates a vector with points
that are spaced logarithmically between decades, which is useful for creating frequency vectors
or data on a logarithmic scale.

2. Create a 5x5 matrix with elements that are random integers between 1 and 10, and then find
the trace of the matrix.

Ans-

A = randi([1, 10], 5, 5);

trace_A = trace(A);

2.Describe the concept of cell arrays in MATLAB and provide an example to create a cell array.

Ans- Cell arrays in MATLAB are data structures that allow you to store arrays of different types
and sizes. Unlike regular arrays, which can only store elements of the same data type and size,
cell arrays can contain heterogeneous data such as strings, numbers, matrices, or even other cell
arrays.
Example- C = {1, 'text', [1, 2, 3];

3.14, magic(3), {'nested', 'cell'}};

4. Take a 3x3 matrix, extract the diagonal elements and find their sum.

Ans- A = [1 2 3; 4 5 6; 7 8 9];

diag_elements = diag(A);

sum_diag = sum(diag_elements);

Group C.

2. Write a MATLAB function that takes a 3D array as input and computes the sum of each 2D
slice along the third dimension. Test your function with a 3x3x3 array and display the results.

Ans- Function –

function slice_sums = sum_slices_3D(array3D)

[rows, cols, depth] = size(array3D);

slice_sums = zeros(rows, cols);

for k = 1:depth

slice_sums = slice_sums + array3D(:, :, k);

end

end

Function test –

array3D = randi(10, 3, 3, 3);

result = sum_slices_3D(array3D);

disp(result);

You might also like