How to run a for-loop with different dimesions?

1 回表示 (過去 30 日間)
Wan-Yi Chiu
Wan-Yi Chiu 2020 年 4 月 22 日
コメント済み: Wan-Yi Chiu 2020 年 4 月 22 日
Let A be a 20 by 1 array. I can separately compute
B_1=mean(A(1:6, 1:1)),
B_2=mean(A(7:15, 1:1)), and
B_3=mean(A(16:20, 1:1)).
How can I program this job using the loop command with respect to different dimensions?

採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 22 日
starts = [1 7 16];
stops = [6, 15, 20];
n = length(starts);
B = zeros(1,n);
for K = 1 : n
B(K) = mean(A(starts(K):stops(K), 1));
end
  1 件のコメント
Wan-Yi Chiu
Wan-Yi Chiu 2020 年 4 月 22 日
Thank you very much.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by