creating matrix using output elements
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
okoth ochola
il 19 Gen 2023
Commentato: Fangjun Jiang
il 20 Gen 2023
Hi, i havecode below which ouputs given values independently. however, i want the ouputs to be under one matrix,what can i add to the code to do this job. B is an n by 1 matrix say B=[1:1:24]'. How can I collect all the values of Hourly_mean to form one matrix? kindly assist. Thank you
B=[1:1:576]'
for k=1:1:numel(B)
Hourly_mean=mean(B(k:24:end))
end
[Hourly_mean]
0 Commenti
Risposta accettata
Fangjun Jiang
il 19 Gen 2023
B=[1:1:576]';
mean(reshape(B,24,[]))
3 Commenti
Steven Lord
il 20 Gen 2023
Let's take a smaller example that demonstrates the technique. Say I want to take the mean of every 6th element of B. We can reshape B into a matrix.
B = 1:24;
C = reshape(B, 6, 4)
Now take the mean along the 2nd dimension.
D = mean(C, 2)
Spot check that D is correct by manually computing the mean of the 3rd, 9th, 15th, and 21st element of B. Does that match D(3)?
sum(B(3:6:24))./4
Fangjun Jiang
il 20 Gen 2023
@Steven Lord, good catch! mean(C,2) is more likely the needed outcome than mean(C).
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!