hello...I am starting learning Matlab by myself. there were some commands I could't understand and will be grateful if you answer me ASAP. I got the additional code (added as jpg file):
clc close all x=(1:0.1:10); y=(x.*sin(x))./exp(x); Ymin=min(y) Xmin=x(y==Ymin) plot (x,y); hold on plot (x,Ymin*(x==x),'r--'); plot (Xmin,Ymin,'*g');
"According to what I learned the operation of == should be implemented on the same size subjecs, eg. scalar==scalar or vector==vector..."
Not according to the MATLAB documentation. In the eq help it states "Numeric or string inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations". When you follow the link in the help it takes you to a page that applies to many mathematical operations, and explains, together with examples, what (different) sizes the inputs arrays can have.
"I specially can't understand what the mid-term Ymin*(x==x) mean"
So try it yourself, take it apart and see what the different parts do. Essentially x==x produces an array the same size as x, but with all values 1 (or true), and then multiplies these ones with Ymin. For example:
>> x = [4,5,6,7]; >> x==x ans = 1 1 1 1 >> 7*(x==x) ans = 7 7 7 7
You could easily have tried that yourself at the command line. Experimenting is a great way to learn things!
Personally I would have made this a bit more explicit:
Note that the "compatible array sizes" behavior changed significantly with MATLAB version R2016b, so you should always check the documentation for your installed MATLAB, not just the publicly accessible online help (which is for the most recent version):