Combining results of a 3D array

4 ビュー (過去 30 日間)
Jonathan
Jonathan 2020 年 3 月 26 日
コメント済み: James Tursa 2020 年 3 月 26 日
Hi everyone,
I have a series of ND arrays of the same size filled with zeroes and ones. I want to combine the array with the following rules:
If at the X and Y position for all arrays there is a zero, the final array will be a zero. If there is a 1 at any location, the final array will have a 1 at that location.
However, I am getting an error message of 'Attempt to grow array along ambiguous dimension.
This is the logic of the code I have so far:
% Assuming S is an array of arrays (implies M x N x P)
% M - number of rows
% N - number of columns
% P - number of such matrices
p = 1;
while (some condition holds true)
S(:,:,p) = (M - y).^2 + (N - x).^2 <= radius.^2;
p = p+1;
update_of_condition;
end
D = zeros(M,N);
index1Loc = sum(S,p-1) ~= 0;
D(index1Loc) = 1; %this is where the error of 'Attempt to grow array along ambiguous dimension.' occurs

採用された回答

James Tursa
James Tursa 2020 年 3 月 26 日
Is any(S,3) what you want?
  2 件のコメント
Jonathan
Jonathan 2020 年 3 月 26 日
I'm not sure since I don't know how to check the output. Will this code add up and compare all the arrays within the ND array?
James Tursa
James Tursa 2020 年 3 月 26 日
Use a small example and see if it does what you want. The result will be a 1 if any of the 3D spots is a 1, and 0 otherwise.

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

その他の回答 (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