Suppressing a function’s command window output
You might try wrapping the call to the function in an evalc: evalc(‘out = func(arg1, arg2);’);
You might try wrapping the call to the function in an evalc: evalc(‘out = func(arg1, arg2);’);
Ellipse article on Wikipedia had a simple JavaScript code to draw ellipses. It uses the parametric form: x(theta) = a0 + ax*sin(theta) + bx*cos(theta) y(theta) = b0 + ay*sin(theta) + by*cos(theta) where (a0,b0) is the center of the ellipse (ax,ay) vector representing the major axis (bx,by) vector representing the minor axis I translated the code … Read more
With R2015a, this question finally has a simple answer (see my other answer to this question for details). For releases prior to R2015a, there is such a built-in (undocumented) function: _mergesimpts. A safe guess at the composition of the name is “merge similar points”. The function is called with the following syntax: xMerged = builtin(‘_mergesimpts’,x,tol,[type]) … Read more
If what you want is for the plot to “grow” point by point: the easiest way is to create an empty plot and then update its XData and YData properties at each iteration: h = plot(NaN,NaN); %// initiallize plot. Get a handle to graphic object axis([min(DATASET1) max(DATASET1) min(DATASET2) max(DATASET2)]); %// freeze axes %// to their … Read more
TLDR: Short Answer As for your question, suppose you have an arbitrary 10-by-10 matrix A. The simplest way to extract the desired sub-matrix would be with an index vector: B = A([1 2 9], [4 6]); Indexing in MATLAB There’s an interesting article in the official documentation that comprehensively explains indexing in MATLAB. Basically, there … Read more
I usually use EYE for that: A = magic(4) A(logical(eye(size(A)))) = 99 A = 99 2 3 13 5 99 10 8 9 7 99 12 4 14 15 99 Alternatively, you can just create the list of linear indices, since from one diagonal element to the next, it takes nRows+1 steps: [nRows,nCols] = size(A); … Read more
Problem statement This is a common struggle, and there is nothing like a test to answer. Here are my assumptions: A well formatted ASCII file, containing two columns of numbers. No headers, no inconsistent lines etc. The method must scale to reading files that are too large to be contained in memory, (although my patience … Read more
Many built-in operations like sum and prod are already able to operate across rows or columns, so you may be able to refactor the function you are applying to take advantage of this. If that’s not a viable option, one way to do it is to collect the rows or columns into cells using mat2cell … Read more
There isn’t a direct way to do this like you’ve attempted. The usual approach is to use “varargs” and check against the number of arguments. Something like: function f(arg1, arg2, arg3) if nargin < 3 arg3 = ‘some default’ end end There are a few fancier things you can do with isempty, etc., and you … Read more
From the context of your question, you wish to find a matrix where each column is an identity vector. For an identity vector, each column in this matrix is a non-zero vector where 1 is set in the position of the vector denoted by each position of y and 0 otherwise. Therefore, let’s say we … Read more