Azzera filtri
Azzera filtri

Addition in 3D matrix

2 visualizzazioni (ultimi 30 giorni)
Orlando Ramirez-Valle
Orlando Ramirez-Valle il 14 Feb 2021
Hello,
How can I sum in 3D using intervals;
example:
(62x50x341) 3d matrix
I want to add the following intervals in 3D:
Intervals; 8,30,31,31,30,31,30,31,31,28,31,29
is it possible to do it in a loop?
Thanks in advance

Risposta accettata

the cyclist
the cyclist il 14 Feb 2021
% Define some pretend data, the size of your original matrix
M = rand(62,50,341);
% Intervals
interval = [8,30,31,31,30,31,30,31,31,28,31,29];
% Get the sizes of M and intervals
[r,c,~] = size(M);
ni = length(interval);
% Calculate endpoints
endpoints = cumsum(interval);
% Calculate starting points
startpoints = [1 endpoints(1:end-1)+1];
% Preallocate an array for the summed intervals
output = zeros(r,c,ni); % Could also get these values from the sizes of the inputs
% Fill the output with the summed intervals
for ii = 1:ni
output(:,:,ii) = sum(M(:,:,startpoints(ii):endpoints(ii)),3);
end
  1 Commento
Orlando Ramirez-Valle
Orlando Ramirez-Valle il 14 Feb 2021
It worked !!!, I really appreciate your help. Thank you

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by