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);

답변 (1개)

Sriram Tadavarty
Sriram Tadavarty 2020년 4월 4일

0 개 추천

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
For more information, look at the clc, clear, close, frpintf and element wise multiplication.
Hope this helps.
Regards,
Sriram

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2020년 4월 4일

답변:

2020년 4월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by