Here is my contribution:
c = b - ones(size(b))*diag(a)
Now speed testing it:
tic
for i = 1:10000
c = zeros(size(b));
b = rand(7,3);
c = b - ones(size(b))*diag(a);
end
toc
The result:
Elapsed time is 0.099979 seconds.
Not quite as fast, but it is clean.
More Related Contents:
- How can I index a MATLAB array returned by a function without first assigning it to a local variable?
- Matrix of unknown length in MATLAB?
- How do you concatenate the rows of a matrix into a vector?
- Octave / Matlab: Extend a vector making it repeat itself?
- How can I accumulate cells of different lengths into a matrix in MATLAB?
- Use a vector as an index to a matrix
- Is MATLAB row specific or column major?
- How to select a submatrix (not in any particular pattern) in Matlab
- Get the indices of the n largest elements in a matrix
- Multiply a 3D matrix with a 2D matrix
- Vectorizing the Notion of Colon (:) – values between two vectors in MATLAB
- Is there a substitute for blockproc in Matlab?
- Matrix “Zigzag” Reordering
- How do I compare all elements of two arrays?
- How can I divide each row of a matrix by a fixed row?
- Sorting entire matrix according to one column in matlab
- Index of max and min value in an array
- How can I count the number of elements of a given value in a matrix?
- How can I sort a 2-D array in MATLAB with respect to one column?
- Octave/Matlab: Adding new elements to a vector
- How do I divide matrix elements by column sums in MATLAB?
- General method to find submatrix in matlab matrix
- MATLAB find and apply function to values of repeated indices
- How to find out if a matrix is singular? [duplicate]
- the easiest way to convert matrix to one row vector [duplicate]
- Extract arbitrarily rotated plane of data from 3D array as 2D array
- MATLAB: Subtracting matrix subsets by specific rows
- How do I convert a 2X2 matrix to 4X4 matrix in MATLAB?
- Efficiently compute a 3D matrix of outer products – MATLAB
- Display matrix with row and column labels