MATLAB: Confusion in Addition: adding 1:4 to a matrix of 1X4 gives resultant matrix of 1X5 additionMATLAB If A = [1 0;0 1] then how would 1:4 + A(:)' = 1 2 3 4 5 Best Answer Because of operator precedence, + has more priority than :. Therefore your expression is equivalent to :1 : (4 + A(:)')which is1 : ([5; 4; 4; 5])Because of the colon rule, only the first element of a vector is considered, the above is thus equivalent to:1 : 5I suspect you may have wanted(1:4) + A(:)'which will result in a 1x4 vector pre-R2016b (or it may error, I can't remember) and in a 4x4 matrix in R2016b or later. Related SolutionsMATLAB: Plot 2 1×4 matrices Here is one way:x = [1 4 4 1];y = [1 1 4 4];figurepatch(x,y,'b')set(gca,'XLim',[0 5],'YLim',[0 5])That last line is only to show create a little space around the rectangle. MATLAB: Fprintf in if statement if x == 1 % where x is assumed as a scalar fprintf('hello')endhelp ifdoc if Related QuestionConvert 1X5 to 3X31D matrix addition weirdnessHow to average 1X5 cellAddtion with 2×1 Vector and 2×3 Matrix
Best Answer