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 visualización (últimos 30 días)
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 comentario
darova
darova el 28 de Feb. de 2020
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

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 28 de Feb. de 2020
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.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by