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.
Tutorialspoint

formating strings

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)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.