Computer Programming and Applications (CPA) - ME-214
Computer Programming and Applications (CPA) - ME-214
(ME-214) Notes
1. Introduction to Arrays
Arrays are used to store and manipulate data in MATLAB.
One-dimensional arrays are called vectors.
Two-dimensional arrays are called matrices.
Arrays can store numbers, characters, or strings.
Key Concepts:
Creating Matrices:
Modifying Elements:
You can change the value of an element by assigning a new value to its index.
matlab
Copy
A(2, 3) = 10; % Changes the element in the 2nd row, 3rd column to 10
Adding Elements:
Deleting Elements:
5. Introduction to Strings
Strings are arrays of characters.
Strings are created using single quotes.
matlab
Copy
str = 'Hello, World!';
String Functions:
strcat: Concatenates strings.
matlab
Copy
str1 = 'Hello';
str2 = 'World';
result = strcat(str1, ' ', str2); % Result: 'Hello World'
strlength: Returns the length of a string.
matlab
Copy
len = strlength(str); % Returns the length of the string
strcmp: Compares two strings.
matlab
Copy
cmp = strcmp(str1, str2); % Returns 1 if strings are equal, 0 otherwise
Deleting Elements:
Introduction to Strings:
7. Practice Problems
Problem 1: Adding Elements to a Vector