Please Explain this code

3 ビュー (過去 30 日間)
Caitlin Stoddard
Caitlin Stoddard 2020 年 4 月 4 日
回答済み: Sriram Tadavarty 2020 年 4 月 4 日
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 日
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by