フィルターのクリア

how to find the correct value of the matrix

2 ビュー (過去 30 日間)
marwa hajji
marwa hajji 2022 年 3 月 17 日
編集済み: Torsten 2022 年 3 月 17 日
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

採用された回答

Chunru
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
into = 1×10
0.1000 0.1000 0.1000 0.2000 0.2000 0.2000 0.2000 0.3000 0.3000 0.3000

その他の回答 (1 件)

Torsten
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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by