0% found this document useful (0 votes)
26 views

CGPR

The document contains 12 MATLAB programming questions and their corresponding solutions. It covers topics like arrays, arithmetic operations, date functions, loops, conditional statements, functions, strings, prime numbers and more. Complete MATLAB code solutions are provided for all the questions asked.

Uploaded by

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

CGPR

The document contains 12 MATLAB programming questions and their corresponding solutions. It covers topics like arrays, arithmetic operations, date functions, loops, conditional statements, functions, strings, prime numbers and more. Complete MATLAB code solutions are provided for all the questions asked.

Uploaded by

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

1. Explain MATLAB workspace Save, Load, Clear all function.

Output: -

Clear Function: -
Save Function: -
2. Write a program in MATLAB to enter two arrays and multiply them.

Input: -

fprintf('this is Array1\n')
Array1=[1 2; 3 4]
fprintf('this is an Array2\n')
Array2=[5 6; 7 8]
fprintf('Result Output\n')
fprintf('%%%%%%%%%%%%%%%%%%%%%\n')
ArrayMultiply=Array1*Array2

Output: -
3. Write a program in MATLAB to perform arithmetic operation.

Input: -

Variable1=[12 13 23; 14 8 6; 27 8 9];


Variable2=2;
fprintf('Result Output:\n')
fprintf('\n')
fprintf('******************\n')
Addition=Variable1+Variable2
Subtraction=Variable1-Variable2
Multiplication=Variable1*Variable2
Division=Variable1/Variable2

Output: -
4. Write a program in MATLAB to enter a date so that program will display a day coming on
that day.

Input: -

fprintf('This is current date\n')


fprintf('09-feb-2018')
fprintf('\n')
fprintf('^^^^^^^^^^^^^^^^^\n')
Date='09-feb-2018';
[DayNumber,DayName]=WeekDay(Date)

Output: -
5. Write a program in MATLAB using while loop.

Input: -

variable=10;
%While loop Exwcution
fprintf('Result output\n')
fprintf('\n')
fprintf('*******************\n')
while(variable<20)
fprintf('The value of variable is:%d\n',variable)
variable=variable+1;
end

Output: -
6. Write a MATLAB program perform switch case.

Input: -

fprintf('Result output\n')
fprintf('\n')
fprintf('***********************\n')
Grade ='A';
switch (Grade);
case 'A'
fprintf('Excellent\n');
case 'B'
fprintf('Well done\n');
case 'C'
fprintf('Well done\n');
case 'D'
fprintf('You Passed\n');
case 'F'
fprintf('Better Try Again\n');
otherwise
fprintf('Invalid Grade\n');
end

Output: -
7. Write a program in MATLAB to comparing two Different values.

Input: -

% comparing two values


fprintf('Result output\n')
fprintf('\n')
fprintf('******************\n')
value1=100;
value2=200;
if(ge(value1, value2))
MAX=value1
else
MAX=value2
end

Output: -
8. Write a program in MATLAB to perform Addition & Subtraction of two vectors.

Input: -

vectorvalue1=[7,11,15,23,9];
vectorvalue2=[2,5,13,16,20];
fprintf('Addition & Subtraction operations\n')
Add=vectorvalue1+vectorvalue2;
Sub=vectorvalue1-vectorvalue2;
fprintf('Result output \n')
fprintf('Result For Addition \n')
disp(Add);
fprintf('Result For Substraction \n')
disp(Sub);

Output: -
9. Write a program in MATLAB declare Global variables and find it average

Input: -

fprintf('Global Variable Declration')


global TOTAL;
TOTAL =10;
nums=[35,45,45,25,33,19,40,34,38,42];
Avg=sum(nums)/TOTAL;
fprintf('Result output\n')
Averageis =(Avg)

Output: -
10. Write a program in MATLAB to perform function

Input: -

function max = mymax(n1,n2,n3,n4,n5)


n1=10;
n2=12;
n3=10;
n4=12;
n5=15;
fprintf('this function claculate the maximum of the five
numbers \n\n')
max =n1;
if(n2>max)
max=n2;
else
if(n3>max)
max=n3;
end
if(n5>max)
max = n5;
fprintf('Result output\n')
maximum vlaue is =(max)
end
end

Output: -
11. Write a program in MATLAB to combine string into a cell Array

Input: -

fprintf('result output\n')
fprintf('student detail\n')
name='Akhilesh Khade';
sem= 'Fourth Sem';
workat = 'Chandrapur';
profile = char(name , sem, workat);
profile = cellstr(profile);
disp(profile)

Output: -
12. Write a program in MATLAB to display all prime number from 1 to 50 using for loop.

Input: -

fprintf('Display prime number \n')


fprintf('result output\n')
for i=2:50
for j=2:50
if(~mod(i,j))
break
end
end
if(j>(i/j))
fprintf('%d is prime \n',i)
end
end

Output: -

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy