MATLAB: Hi,,,lets say I have a 3*4 matrix.. I want to add row-wise elements. How to do that? TIA addadditionmartix operationmatrixrow matrix example : A=[1 0 1 0 ; 0 1 0 0 ; 1 1 1 0]; How can I add the elements row wise? Best Answer bsxfun(@xor,A,A)does not have index to point operation along a given matrix dimension, bsxfun(@xor,A,A,2) doesn't work.However, for vertical xor you can do:[sz1 sz2]=size(A)B=xor(A(1,:),A(2,:));for k=2:1:sz1-1 B=xor(B,A(k+1,:)); endand horizontal xor:[sz1 sz2]=size(A)B=xor(A(:,1),A(:,2));for k=2:1:sz2-1 B=xor(B,A(:,k+1)); end1 is vertical, 2 is horizontalPerhaps you are going to repeat these operations, you may want to turn these 2 into a single function with input the dimension to calculate xor along.In case you don't know how to, just ask as comment in this question and I'll have a look.If you find this answer of any help solving your question,please click on the thumbs-up vote link,thanks in advanceJohnjgb2012@sky.com Related SolutionsMATLAB: Element Wise Multiplication for varying matrix sizes FirstMatrix .* repmat(SecondVector, size(FirstMatrix,1), 1) MATLAB: Logical operators on a logical matrix all(A,2)any(A,2) Related QuestionHow to multiply elements of a cell array with each otherHi,,is there anyone who could suggest any way of calculating the weight of a matrix row-wiseExclusive or between two different matrix size
Best Answer