I have some problem with reading data in loop
cx_sum(Q) and cy_sum(Q) are not working in loop.
cx_sum and cy_sum have value 1x1622.
for Q = 1:1621
CY_sum99 = mean(cy_sum(Q),'omitnan')
CX_sum99 = mean(cx_sum(Q),'omitnan')
end
So can you solve this problem? Thank you

 採用された回答

dpb
dpb 2022 年 7 月 20 日

0 投票

But they are .. just that cy_sum(Q) is the single element of the array on each pass and the mean of a single number is the number and so the last computed value at the end of the loop is the last element of each array (if not NaN) .
You're looking for simply writing
CY_mn=mean(cy_sum,'omitnan');
CX_mn=mean(cx_sum,'omitnan');
probably...but that's guessing.

3 件のコメント

Mingde
Mingde 2022 年 7 月 20 日
編集済み: Mingde 2022 年 7 月 20 日
thank you for you answer. if i want to change loop Q= 1:270. So are cy_sum and cx_sum working until 270? because I think if we don't need to put loop from start to end, it will show the whole data in there.
for Q = 1:270
CY_sum99 = mean(cy_sum,'omitnan')
CX_sum99 = mean(cx_sum,'omitnan')
end
I see cy_sum and cx_sum are working from 1:1622
so I want it to work in specific (start:end)
dpb
dpb 2022 年 7 月 20 日
編集済み: dpb 2022 年 7 月 20 日
No, you don't want the loop still -- you want to sub-reference the portion of the array desired.
That would be
Nlower=1; % programming practice -- don't bury "magic" numbers in code;
Nupper=270; % use variables that can change
CX_mn_UL=mean(cx_sum(Nlower:Nupper),'omintnan');
It doesn't matter over what elements you loop, the above computes the same result as the mean 270 times since you reference the full variable inside the loop.
I strongly recommend spending time reading the "Getting Started" tutorial section in the local documentation on MATLAB syntax and referencing arrays, etc., ...
Mingde
Mingde 2022 年 7 月 20 日
Thank you so much. I appreciate it your answer.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2022 年 7 月 20 日

編集済み:

dpb
2022 年 7 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by