duplicated result in for loop

1 回表示 (過去 30 日間)
Tino
Tino 2019 年 6 月 4 日
編集済み: Jan 2019 年 6 月 4 日
powerr = [ ...
0.6164 3.4161 0.9950 3.4117
3.1654 0.4123 4.2391 1.0198
0.5745 3.0364 1.3191 3.1129
2.9883 0.7348 3.8730 0.4123
0.9381 3.3749 2.0421 3.5014
2.1817 1.0630 3.0643 0.9487];
k = 3;
m = k;
croppedz = powerr(1:end-mod(end, 2*m), :);
result = zeros(size(croppedz, 1) / 2 / m, size(croppedz, 2));
for lol = 1 : size(croppedz, 2)
hh = powerr(1:3);
gg = powerr(4:6);
n = m*fix(numel(hh)/m);
result (:, lol) = sum(reshape(sort(hh(1:n), col),m,[]),1) ./ ...
sum(reshape(sort(gg(1:n), col),m,[]),1);
end
disp(result)
I am getting the result
0.7132 0.7132 0.7132 0.7132
instead
0.7132 1.3271 0.7298 1.5515
thanks in advance
Tino
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 4 日
powerr mat code?
Tino
Tino 2019 年 6 月 4 日
Sorry that was a mistake it is powerr

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 6 月 4 日
編集済み: Jan 2019 年 6 月 4 日
The body of the loop does not depend on the loop counter lol. Therefore you must get the same value for each iteration.
A bold guess of what you want instead:
for lol = 1 : size(croppedz, 2)
hh = powerr(1:3, lol);
gg = powerr(4:6, lol);
...

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by