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