how to find the correct value of the matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chunru
2022-3-17
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 个评论
更多回答(1 个)
Torsten
2022-3-17
编辑:Torsten
2022-3-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!