In MATLAB, given the 36 x 17 matrix A, I want to average every 6 elements of each column, creating a 6 x 17 matrix B. I can achieve this using the following code:
A
B
A = rand(36, 17); B = [mean(A(1:6:36,:)); mean(A(2:6:36,:)); mean(A(3:6:36,:)); mean(A(4:6:36,:)); mean(A(5:6:36,:)); mean(A(6:6:36,:))];
Although the syntax is not too long, I was interested to know if I can achieve the same result in a more compact, efficient way (i.e. using bsxfunor arrayfun?)
bsxfun
arrayfun
, reshape, 6, 3D, mean , 3D / 2D -
reshape
6
3D
mean
2D
B = squeeze(mean(reshape(A,6,[],size(A,2)),2))
( Divakar, ):
N = size(A, 1)/6; B = (repmat(eye(6), 1, N)*A)./N;
, 2D :
n = 6; % average every n-th element C = zeros(size(A, 1) - n + 1, 1); C(1:n:size(A, 1), :) = 1/(size(A, 1) / n); B = conv2(A, C, 'valid');
, , , , , 3D, Divakar ( ), , .
Source: https://habr.com/ru/post/1675653/More articles:Using a C-string const script as a compiler error message - c ++Python + splinter + http: Error - httplib.ResponseNotReady - pythonHow to make a simple PHP API handler? - jsonProgrammatically switch stereo audio channels (left <> right) in the headphones using C # - c #how to open two tabs in python splinter - pythonΠΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π»ΠΈ, ΡΡΠΎΠ±Ρ Π²ΡΠΎΡΠΈΡΠ½ΡΠΉ Π²ΠΈΠ΄ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ ΠΈΠ·ΠΌΠ΅Π½ΡΠ»ΡΡ Π² ΡΠ°ΡΠΊΠ°Π΄ΡΠΎΠ²ΠΊΠ΅, ΠΏΠΎΡΠΊΠΎΠ»ΡΠΊΡ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ "Π²ΠΈΠ΄ ΠΊΠ°ΠΊ" ΠΈΠ·ΠΌΠ΅Π½ΡΡΡΡΡ? - iosΠ°ΡΠ΄ΠΈΠΎ Blob Π½Π΅ ΡΠ°Π±ΠΎΡΠ°Π΅Ρ Π² IOS/Safari - node.jsRunning dotnet ef migration for class library gives error MSB4006 - entity-framework-coreProject Date Re-editing group outputs in R - regexΠΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ Π°ΡΠΈΠ½Ρ ΡΠΎΠ½Π½ΠΎΠΉ ΡΠ΅Π³ΠΈΡΡΡΠ°ΡΠΈΠΈ Π² Log4J2 Π² Spark Scala Application - sbtAll Articles