% Create a 2D matrix with consecutive elements X=5; Y=7; disp('Creating 2D test Matrix'); fflush(1); P=reshape(1:(X*Y),[X Y]); disp('Now lets set some slices along the first dimension'); S=reshape(1:Y,[1 Y]) * -1 fflush(1); for i=1:X p=P; % Clone the array fprintf(2,'About to subassign (%d,:)\n',i); p(i,:)=S; % Set the slice fprintf(2,'Verifying assignment\n'); for I=1:X for J=1:Y if(i ~= I) if (p(I,J) ~= I+(J-1)*X) error('Mismatch Encountered!'); end; else if (p(I,J) ~= -1*J) error('Mismatch found!'); end; end end end end disp('Now lets set some slices along the second dimension'); S=reshape(1:(X),[X 1]) * -1 fflush(1); for j=1:Y p=P; % Clone the array fprintf(2,'About to subassign (:,%d)\n',j); p(:,j)=S; % Set the slice fprintf(2,'Verifying assignment\n'); for I=1:X for J=1:Y if(j ~= J) if (p(I,J) ~= I+(J-1)*X) error('Mismatch encountered!'); end; else if (p(I,J) ~= -1*I) error('Mismatch found!'); end; end end end end % Create a 3D matrix with consecutive elements X=5; Y=7; Z=11; disp('Creating 3D test Matrix'); fflush(1); P=reshape(1:(X*Y*Z),[X Y Z]); disp('Now lets set some slices along the first dimension'); S=reshape(1:(Y*Z),[Y Z]) * -1 fflush(1); for i=1:X p=P; % Clone the array fprintf(2,'About to subassign (%d,:,:)\n',i); p(i,:,:)=S; % Set the slice fprintf(2,'Verifying assignment\n'); for I=1:X for J=1:Y for K=1:Z if(i ~= I) if (p(I,J,K) ~= I+(J-1)*X+(K-1)*X*Y) error('Mismatch Encountered'); end; else if (p(I,J,K) ~= -1*(J+(K-1)*Y)) error('Mismatch found!'); end; end end end end end disp('Now lets set some slices along the second dimension'); S=reshape(1:(X*Z),[X Z]) * -1 fflush(1); for j=1:Y p=P; % Clone the array fprintf(2,'About to subassign (:,%d,:)\n',j); p(:,j,:)=S; % Set the slice fprintf(2,'Verifying assignment\n'); for I=1:X for J=1:Y for K=1:Z if(j ~= J) if (p(I,J,K) ~= I+(J-1)*X+(K-1)*X*Y) error('Mismatch Encountered'); end; else if (p(I,J,K) ~= -1*(I+(K-1)*X)) error('Mismatch found!'); end; end end end end end disp('Now lets set some slices along the third dimension'); S=reshape(1:(X*Y),[X Y]) * -1 fflush(1); for k=1:Z p=P; % Clone the array fprintf(2,'About to subassign (:,:,%d)\n',k); p(:,:,k)=S; % Set the slice fprintf(2,'Verifying assignment\n'); for I=1:X for J=1:Y for K=1:Z if(k ~= K) if (p(I,J,K) ~= I+(J-1)*X+(K-1)*X*Y) error('Mismatch Encoutnered!'); end; else if (p(I,J,K) ~= -1*(I+(J-1)*X)) error('Mismatch found!'); end; end end end end end disp('Subassignment Validation Complete'); %EOF