how to find the correct value of the matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
marwa hajji
el 17 de Mzo. de 2022
anyone help me , when I excute this example , I didn't found in the matrix ''into'' the correct value.
x=[1 1 1 2 2 2 2 3 3 3];
d=0.1:0.1:1;
for ii=1:10
if ii==1:3
into(1:3)=x(1:3)*(d(1));
elseif ii==4:7
into(4:7)=x(4:7)*(d(1));
else
into(8:10)=x(8:10)*(d(1));
end
end
0 comentarios
Respuesta aceptada
Chunru
el 17 de Mzo. de 2022
x=[1 1 1 2 2 2 2 3 3 3];
d=0.1:0.1:1;
into = zeros(size(x));
for ii=1:10
if ii<=3
into(ii)=x(ii)*(d(1));
elseif ii<=7
into(ii)=x(ii)*(d(1));
else
into(ii)=x(ii)*(d(1));
end
end
into
0 comentarios
Más respuestas (1)
Torsten
el 17 de Mzo. de 2022
Editada: Torsten
el 17 de Mzo. de 2022
into = zeros(10,1);
into(1:3)=x(1:3)*d(1);
into(4:7)=x(4:7)*d(1);
into(8:10)=x(8:10)*d(1);
or simply
into = x*d(1);
You can also use your loop, but as
into = zeros(10,1);
for i = 1:10
if i <= 3
into(i) = x(i)*d(1);
elseif i >= 4 & i <= 7
into(i) = x(i)*d(1);
else
into(i) = x(i)*d(1);
end
end
But as said, it's not necessary to make it so difficult.
into = x*d(1)
is the best solution.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!