How to calculate multiple array at once?

3 ビュー (過去 30 日間)
Xiao Xiong Thng
Xiao Xiong Thng 2020 年 9 月 25 日
回答済み: Image Analyst 2020 年 9 月 25 日
Hi Guys! I'm trying to do a MeanVoltage = mean(B0006.cycle(1:20).data.Voltage_measured) to store 1x20 data of mean voltage from B0006.cycle(1).data.Voltage_measured to B0006.cycle(20).data.Voltage_measured. Any recommendation? Thank you in advance!
PS: I got 1200+ data in the actual file, too much work to do it line by line.

採用された回答

Dana
Dana 2020 年 9 月 25 日
load NEEDHELP
n = numel(TEST);
meanVolt = zeros(1,n);
for j = 1:n
meanVolt(j) = mean(TEST(j).data.Voltage_measured(1:20));
end
  1 件のコメント
Xiao Xiong Thng
Xiao Xiong Thng 2020 年 9 月 25 日
Thank you so much Dana!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 9 月 25 日
Try this:
s = load('needhelp.mat')
B0006 = s.TEST % Array of 20 structs
% Wants MeanVoltage = mean(B0006.cycle(1:20).data.Voltage_measured);
% However, there is no cycle field. So try it this way:
for k = 1 : length(B0006)
MeanVoltage(k) = mean(B0006(1).data.Voltage_measured);
end
MeanVoltage % Report to command window.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by