フィルターのクリア

Addition in 3D matrix

2 ビュー (過去 30 日間)
Orlando Ramirez-Valle
Orlando Ramirez-Valle 2021 年 2 月 14 日
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

採用された回答

the cyclist
the cyclist 2021 年 2 月 14 日
% 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 件のコメント
Orlando Ramirez-Valle
Orlando Ramirez-Valle 2021 年 2 月 14 日
It worked !!!, I really appreciate your help. Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by