Please Explain this code
1 view (last 30 days)
Show older comments
clc;
clear all;
close all;
x=1:1:10;
y=5:5:50;
z=x.*y;
fprintf('%i\t',x);
fprintf('\n');
fprintf('%i\t',y);
fprintf('\n');
fprintf('%i\t',z);
0 Comments
Answers (1)
Sriram Tadavarty
on 4 Apr 2020
Hi Caitlin,
Here is the annotated code with the explanation:
clc; % Clear command window
clear all; % Clears all the variables in the memory
close all; % Closes all the opened figures
x=1:1:10; % Defines a variable x from 1 to 10, in steps of 1 (i.e. 1, 2, 3, ..., 9, 10)
y=5:5:50; % Defines a variable y from 5 to 50, in steps of 5 (i.e. 5, 10, 15, ..., 45, 50)
z=x.*y; % Performs element wise matrix multiplication for x and y (i.e. (1*5), (2*10), (3*15), ..., (9*45), (10*50)), and assigns to z
fprintf('%i\t',x); % Prints the values in x with a tab spacing mentioned with \t
fprintf('\n'); % Prints a new line
fprintf('%i\t',y); % Prints the values in y with a tab spacing
fprintf('\n'); % Prints a new line
fprintf('%i\t',z); % Prints the values in z with a tab spacing
Hope this helps.
Regards,
Sriram
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!