Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
%Scalar Variable creation
% i)assigns the value 10 to a
a =10
% ii)b is assigned 2.5*10^23
b =2.5*10^23
% iii) c is assigned the complex number 2+3i
c=2+3i
% iv)d is assigned the value e^((2*pi/3)j)
d= exp(2*pi/3 *j)
%Scalar Variable creation
% i)assigns the value 10 to a
a =10
% ii)b is assigned 2.5*10^23
b =2.5*10^23
% iii) c is assigned the complex number 2+3i
c=2+3i
% iv)d is assigned the value e^((2*pi/3)j)
d= exp(2*pi/3 *j)
str = 'The range for int8 is:\n\t %d to %d ';
% the \t used the print something like :
% output
% instead of:
% output
sprintf(str, intmin('int8'), intmax('int8'));
% Whave we have done here is : printing a string then go to the next line (\n) then add some tabs (\t) then print the two nubers (%d a_string %d)
% here are two ways creat a 2 dim array with strings
doc_profile = ['Yasmine Najmi '; ...
'Sr. Surgeon '; ...
'RN Tagore Cardiology Research Center'];
doc_profile = char('Yasmine Najmi', 'Sr. Surgeon', ...
'RN Tagore Cardiology Research Center');
%FORMATTING STRINGS
A = pi*1000*ones(1,5)
% N = (3111.6 3222.6 3333.6 3444.6 3555.6) ;
sprintf(' %f \n %.2f \n %+.2f \n %11.4f \n %013.2f \n', A)
% the term % x.yf applied to the number
% 3141.592654 means print this number with y digit after the dot
% lets say the result is a float with n digits
% x.yf print this new nuber and adds n-x tabs befor it
sprintf("###########################")
students = {'Zara Ali', 'Neha Bhatnagar', ...
'Monica Malik', 'Madhu Gautam', ...
'Madhu Sharma', 'Bhawna Sharma',...
'Nuha Ali', 'Reveva Dutta', ...
'Sunaina Ali', 'Sofia Kabir'};
% The strrep function searches and replaces sub-string.
%this one replace evry 'v' with 'n'
corrected_name = strrep(students(8), 'v', 'n')
students(8) = corrected_name
% Display first names
first_names = strtok(students)
polyder([4 5 6 7 8 0 ]);
A = [1 1 1 ; 2 2 2 ; 3 3 3 ] ;
B = [1 1 1 ; 2 2 2 ; 3 3 3 ] ;
D = [1 1 1 1 ; 2 2 2 2 ; 3 3 3 3] ;
% COMMENT
numel(A);
size(A);
det(A);
inv(A);
x = 3 ;
y = 4 ;
x+y ;
A*B;
A.*B;
A(3,2);
C = repmat(A, 3, 4);
C([2, 6], :) ;
C([2, 6], [3, 7]);
C([2:4:end], [3, 7]);
2:3:100;
ans; % calls most recent answer
sqrt(136);
163 / ans;
% multiple asignments
a = 2; b = 7; c = a * b ;
% the command who tells you all the variables you have used
% the command whos tells you more about the varibles (their size, Bytes, Class)
initial_velocity = 0;
acceleration = 9.8;
time = 20;
final_velocity = initial_velocity + acceleration * time;
% the format command
pi;
x = 7 + 10/3 + 5 ^ 1.22;
format long; %16 digits after decimal
x = 7 + 10/3 + 5 ^ 1.22;
pi;
format short % the default format 4 places
x = 7 + 10/3 + 5 ^ 1.22;
pi;
%The format bank command rounds numbers to two decimal places
format bank
daily_wage = 177.45;
weekly_wage = daily_wage * 6 ;
format short e % the e in the output is 10
4.678 * 4.9;
% you can also use the format long e
%The format rat command gives the closest rational expression resulting from a calculation
format rat
4.678 * 4.9;