Main Content

Binary Operations with Arrays

Most operations simply cycle through the array dimensions, doing pointwise operations. Assume A and B are umat (or uss, or ufrd) arrays with identical array dimensions (slot 3 and beyond). The operation C = fcn(A,B) is equivalent to looping on k1, k2, ..., setting

C(:,:,k1,k2,...) = fcn(A(:,:,k1,k2,...),B(:,:,k1,k2,...)) 

The result C has the same array dimensions as A and B. The user is required to manage the extra dimensions (i.e., keep track of what they mean). Methods such as permute, squeeze and reshape are included to facilitate this management.

In general, any binary operation requires that the extra-dimensions are compatible. The umat, uss and ufrd objects allow for slightly more flexible interpretation of this. For illustrative purposes, consider a binary operation involving variables A and B. Suppose the array dimensions of A are n1××nlA and that the array dimensions of B are m1××mlB. By MATLAB® convention, the infinite number of singleton (i.e., 1) trailing dimensions are not listed. The compatibility of the extra dimensions is determined by the following rule: If lA = lB, then pad the shorter dimension list with trailing 1's. Now compare the extra dimensions: In the k-th dimension, it must be that one of 3 conditions hold: nk = mk, or nk = 1, or mk = 1. In other words, non-singleton dimensions must exactly match (so that the pointwise operation can be executed), and singleton dimensions match with anything, implicitly through a repmat.