Can anyone please explain that what each command is showing in the following program? How to select the dimesions? As well as recommend something to study the loops.

1 次查看(过去 30 天)
X=x(2:21); (what is the meaning of x(2:21))?
Y=y(2:21);
M=zeros([20,10]);
for i=1:20
for j=1:10
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x(i);
elseif j==3
M(i,j)=y(i);
elseif j==4
M(i,j)=x(i)^2;
elseif j==5
M(i,j)=y(i)^2;
elseif j==6
M(i,j)=x(i)*y(i);
elseif j==7
M(i,j)=x(i)^2*y(i);
elseif j==8
M(i,j)=y(i)^2*x(i);
elseif j==9
M(i,j)=x(i)^3;
else
M(i,j)=y(i)^3;
end
end
end
X=X';
  1 个评论
darova
darova 2020-2-28
X=x(2:21); (what is the meaning of x(2:21))?
Why don't just try?
x = 1:24 % create some data
x =
Columns 1 through 9
1 2 3 4 5 6 7 8 9
Columns 10 through 18
10 11 12 13 14 15 16 17 18
Columns 19 through 24
19 20 21 22 23 24
X = x(2:21) % choose elements from 2 to 21
X =
Columns 1 through 9
2 3 4 5 6 7 8 9 10
Columns 10 through 18
11 12 13 14 15 16 17 18 19
Columns 19 through 20
20 21

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2020-2-28
I recommend that you go through the free Matlab Onramp tutorial to learn the basics of matlab. The code you show is very basic (if very poorly written) and if you struggle to understand it, you will really struggle with matlab.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by