MATLAB Answers

Create array with average values

2 ビュー (過去 30 日間)
Niet hier
Niet hier 2020 年 3 月 16 日
コメント済み: Niet hier 2020 年 3 月 16 日
I have a device that measures 12 different temperatures at different places and stores it in a 1D array.
The 1D array consits of 480 elemts, so every sensor measured 480/12 = 40 times.
To get the average value of the first 5 measurements per sensor I have to calculate the average of element 1,13,25,37,49 and 2,14,26,38,50 and 3,15,27,39,51 and 4,16,28,40,52 ......12,24,36,48,60. This was succesfully done in Matlab.
Now i have to calculate the average of the next 5 measurements of the device. The average of sensor 1 should be calculated with elelemts 61,73,85,97,109 and sensor 2 needs elements 62,74,86,98,110 etc....
when these average values are calculated i want to get 40/8 = 5 average values per sensor so 12*5 = 60 elements in total.
The resulting array should look like (av=average, number is sensor) :
av1,av2,av3,av4,av5,av6,av7,av8,av9,av10,av11,av12,av1,av2,av3,av4,av5,av6........ (array length =60)

  0 件のコメント

サインイン to comment.

採用された回答

Jon
Jon 2020 年 3 月 16 日
編集済み: Jon 2020 年 3 月 16 日
Use reshape. Say data is a 480 element vector
X = reshape(data,12,40)
Then if you want the average over all the data you can just average across rows
Xmean = mean(X,2)
If you want the average of the first 5 samples then the next 5 etc, you can just average over the selected columns,
Something like this
data = randn(480,1)
X = reshape(data,12,40)
avgResults = zeros(12,8); % preallocate array to hold 5 sample averages
for k = 1:8
col = (k-1)*5+1; % column number
avgResults(:,k) = mean(X(:,col:col+4),2) % average over kth group of 5
end

  1 件のコメント

Niet hier
Niet hier 2020 年 3 月 16 日
Thanks!!!

サインイン to comment.

その他の回答 (1 件)

Arthur ROUÉ
Arthur ROUÉ 2020 年 3 月 16 日
You can reshape you 1D array to get sensor in rows and time in columns.
Data = reshape(Data, 12, 40)
and then apply mean function
% For 5th to 10th measurement
mean(Data(:,5:10), 2)
The result is a 12x1 array where each line is the mean value for each sensor.

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2019a

Translated by