![]() For relatively small arrays, all of the methods are very fast and I would opt for code clarity over performance.Specifically the original loop in your question versus implicit expansion with either vecnorm or the manual calculation. Since you asked for performance, here is a simple benchmark for testing the speed of these different methods. If you have MATLAB R2017b or newer, and again no compatability concerns, you can use vecnorm, which can be used in place of the manual norm calculation S = S. Manual expansion using repmat (all MATLAB versions) S = S. Implicit expansion using bsxfun (all MATLAB versions) S = bsxfun( S, nrm ) Implicit expansion (MATLAB R2016b or newer) S = S. Now we have several options for division: Note that if there's a possibility of your matrix S only having 1 row, you should ecplicitly enforce column-wise summation using nrm = sqrt(sum(x.^2,1)). What's useful for us is that sum works column-wise by default, so the column-wise norm is defined like so: nrm = sqrt( sum( x.^2 ) ) I've used (:) here to show that norm is calculated over the whole matrix. We can just manually calculate the norm and divide column-wise.īy definition, norm(x) = sqrt( sum( x(:).^2 ) ). sqrt(sum(S.^2,1)) Įdit: See benchmark at the bottom for performance benchmark of alternatives. If you have MATLAB 2016b or newer, and no compatibility concerns, I would use S = S. MATLAB: How do you call a "cross-section" of an m-dimensional array?.subplots with different colormaps matlab.need matlab code for M-QAM modulation,demodulation implementation without toolbox.restore jTable focus and position after removing a row from table model.What image file type is expected by Matlab Stereo Camera Calibrator app?.Multiscale Morphological Image Simplification in Matlab.Get submatrix made from random rows and columns of large matix. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |