Computer Programming and Applications MATLAB-beginner
Computer Programming and Applications MATLAB-beginner
applications MATLAB-beginner
Introduction
Write MATLAB code to manually enter a matrix consisting of four rows and three
columns.
Entering Matrices
Using the zeros, ones, or rand Functions:
Entering Matrices
Using the zeros, ones, or rand Functions:
Write a program in MATLAB that generates a 4x4 matrix in three ways: the first
matrix should be composed of zeros, the second of ones, and the third of random
decimal values.
Deleting Rows or Columns.
Transpose
Change the value of an element in an array
Questions
1- Define the matrix and explain its most important properties.
2- Write MATLAB code to manually enter a matrix consisting of four rows and
three columns. Then perform a transpose between the rows and columns,
delete the second row, and replace the first element in the array with the
number 100.
Solutions
Computer programming and
applications MATLAB-beginner
Built in functions
Write a MATLAB program that checks if a given number is odd, even, or zero.
Conditional statements: Switch-case
A switch block is familiar to if-elif-else-end statements. It works as same as in
other languages except for syntax. But there are few key differences between
them. A switch block conditionally executes one set of statements from several
choices. Each choice is covered by a case statement.
Questions
1-Write a MATLAB program that classifies a student's grade based on their
score.
2-Write a MATLAB program that checks if a given number is positive.
3-Write a MATLAB program that determines the day of the week based on a
user-inputted number (1 for Monday, 2 for Tuesday, etc.).
4-Give me a programming example for each:
IF
If_Else
If_elseIf_Else
Switch_case
Solutions
Computer programming and
applications MATLAB-beginner
Repetition statementsents
1- for loop: The for loop iterates over a sequence of values and executes a
block of code for each value in the sequence.
2- while loop: The while loop repeats a block of code as long as a specified
condition is true.
for Statement: Example of printing numbers
The following example is to print numbers from 1 to 5 using for statement
using a for statement in MATLAB does shorten and simplify the process of
writing repetitive print instructions or any repetitive task.
for Statement: Sum of Numbers Example
Explanation:
total is initialized to zero.
The for loop iterates over integers from 1 to 10.
In each iteration, the current value of i is added to total.
After the loop, the sum of the numbers from 1 to 10 is displayed.
for Statement:
Write a MATLAB program to separate elements in the given array into two
arrays - one containing elements larger than ten and the other containing
elements smaller than ten.
for Statement:
Write a MATLAB program that prompts the user to enter a number and then
prints the number repeatedly, with the number of repetitions equal to the
value of the entered number.
while Statement:
while loop: The while loop repeats a block of code as long as a specified
condition is true.
This loop will print the numbers 1 to 5.
while Statement:
Write a program that prints numbers from 1 to 10 using a while loop.
1-Data Visualization
2-Communicating Results
3-Exploratory Data Analysis
4-Debugging and Testing
Basic Plotting
Basic Plotting
Basic Plotting
Multiple Data Sets in One Graph
Specifying Line Styles and Colors
Multiple Plots in One Figure
Questions
1- Define basic plotting in MATLAB and explain its benefits.
2- Using basic plotting in MATLAB, create a plot of the sine function.
3- Using basic plotting in MATLAB, create a plot of the cos function.
Solutions