MATLAB Answers

Can someone explain this Code?

3 ビュー (過去 30 日間)
Ahmet Burak
Ahmet Burak 2021 年 6 月 15 日
回答済み: Mouhamed Niasse 2021 年 6 月 15 日
Hi,
I have the following code on MATLAB, i don't know is it working properly or not. Would you help me to understand the complete content of code and how to make it work right?
clear, clc
for i=1:2:5
for j=1:2:5
x=x+3
xt=[xt x];
y=y+x
yt=[yt y];
end
end
  1 件のコメント
James Tursa
James Tursa 2021 年 6 月 15 日
Maybe you could tell us what the code is supposed to do?

サインインしてコメントする。

回答 (1 件)

Mouhamed Niasse
Mouhamed Niasse 2021 年 6 月 15 日
Hello,
Here is what i achieved to help you understand your algorithm. You can run the code and track how variables evolve through the execution.
"clear" and "clc" are just used to clean the workspace variables and the command window before your code execution.
clear
clc
%initialize x,y,xt,yt
x=0
xt=0
y=0
yt=0
%Here you enter the main loop
for i=1:2:5
disp(['increment i=',num2str(i)])
for j=1:2:5
disp(['increment j=',num2str(j)])
x=x+3
xt=[xt x]
y=y+x
yt=[yt y]
end
end
%final values
x_final=x
xt_final=xt
y_final=y
yt_final=yt

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by