-
Notifications
You must be signed in to change notification settings - Fork 0
/
LAB3.m
65 lines (49 loc) · 1.49 KB
/
LAB3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
clear;
clc;
%% Cell Arrays
% Create a cell array containing various data types (numbers, text, and variables).
% Access and display specific elements within the cell array.
cellArray = {12 , 'Mohamed', [1 2 3]};
disp(cellArray);
disp(cellArray(2));
%% Structures
% Create a simple structure to store information about a person (name, age, city).
% Access and display the structure fields.
person.Name = 'Mohamed';
person.Age = 20 ;
person.City = 'Cairo' ;
disp(person);
%% Character Data
% Create a character array with your name.
% Concatenate your name with another character array.
% Display the results.
name1 = 'Mohammed ';
name2 = 'Ezzelrgal';
conName = [name1 name2] ;
disp(conName);
%% Conditional Statements (If)
% Write an if statement that checks if a number is even or odd.
% Display a message based on the result of the if statement.
number = input("Please enter the number: ");
if rem(number,2)==0
fprintf('%d is an even number\n',number);
else
fprintf('%d is an odd number\n',number);
end
%% For Loops
% Create a for loop to generate a sequence of numbers (e.g., 1 to 10).
% Display the numbers within the loop.
num = 1;
for num = num:10
disp(num)
end
%% Basic Plotting
% Generate data for a simple plot (e.g., a sine wave).
% Plot the data with proper labels and a legend.
x = linspace(0,2*pi,100);
y = sin(x);
plot(x,y,'r');
xlabel('x-axis');
ylabel('y-axis');
title('Sin Wave Function');
legend('sin wave');