- Consider that M need not be a multiple of 2
- Reshape the [M x N] array to a [2 x M/2 x N] array
- Sum over the first dimension and divide by 2
- Remove the first dimension to get a 2D matrix again
Hi i'm new to Matlab. I have a matrix of 3985* 720, i want to produce a new matrix from this by averaging every 2 rows (1992*720), i would appreciate if someone can help me on this .
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Duminda Vidana Gamage
am 27 Sep. 2017
Kommentiert: Jan
am 27 Sep. 2017
Hi i'm new to Matlab. I have a matrix of 3985* 720, i want to produce a new matrix from this by averaging every 2 rows (1992*720), i would appreciate if someone can help me on this .
0 Kommentare
Akzeptierte Antwort
Jan
am 27 Sep. 2017
Bearbeitet: Jan
am 27 Sep. 2017
data = rand(3985, 720);
nOut = floor(size(data, 1) / 2);
dataCut = data(1:2*nOut, :);
dataAvg = sum(reshape(dataCut, 2, nOut, []), 1) * 0.5;
dataAvg = reshape(dataAvg, nOut, []); % Or: squeeze(dataAvg)
Explanation:
1 Kommentar
Jan
am 27 Sep. 2017
Please open a new thread for a new question. Then include the current code and explain, what "does not work" means. The solution will be something like this:
Base = 'C:\YourPath';
FolderList = dir(Base);
FolderList = FolderList([FolderList.isdir]);
for iFolder = 1:numel(FolderList)
aFolder = fullfile(Base, FolderList(iFolder).name);
... Do what you want
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!