Addition in 3D matrix

2 visualizaciones (últimos 30 días)
Orlando Ramirez-Valle
Orlando Ramirez-Valle el 14 de Feb. de 2021
Comentada: Orlando Ramirez-Valle el 14 de Feb. de 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

Respuesta aceptada

the cyclist
the cyclist el 14 de Feb. de 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 comentario
Orlando Ramirez-Valle
Orlando Ramirez-Valle el 14 de Feb. de 2021
It worked !!!, I really appreciate your help. Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by