What is Matlab's colon operator called? - matlab

When teaching people about Matlab, it would be very nice if I could refer to Matlab's colon operator as something other than just "the colon operator". As you can read on this Mathworks blog, the operator has a number of different contexts. I'm referring specifically to the first use on that list, creating a list of numbers.
Does anyone have a clever phrase they use to refer to this operation?

I would call it the "range operator".

Linear Space Vector Generator would also do I think ...

Related

MATLAB: Error in array2table

I'm not able resolve this error i face when running MATLAB's array2table function
The VariableNames property must be a cell array, with each element
containing one nonempty character vector.
array2table([1,2,3],'VariableNames',{"str1", "str2", "str3"})
I had a read at MATLAB's array2table documentation and my syntax mimick's MATLAB's give examples, hence i can't figure out where i went wrong. Would appreciate some help.
Rephrasing the error message: String and character arrays are different things. You're using cells of strings but the function expects you to use cells of characters. i.e.
array2table([1,2,3],'VariableNames',{'str1', 'str2', 'str3'})
Relevant documentation for further understanding: Characters and Strings

What is the difference between comma separated or not MATLAB function return?

I forgot commas between some returns of a function in MATLAB and it did not complain.
function [returnA, returnB]=foo(paramA)
returnA=ones(1,10).*paramA;
returnB=magic(4);
end
function[]=voo()
%typing the return as this
[A,B]=foo(5);
%gives the same result as
[A B]=foo(5);
end
My question is: is it exactly the same behavior? I was not able to find it in documentation
Yes, it is the same behavior, as seen with the code you provide in your question.
As #LuisMendo points out in the comments, if you look at the MATLAB's lint (aka Code Analyzer) message in the editor you'll see:
Best practice is to separate output variables with commas
Which implies that both syntaxes are valid. As to why this is the case I'm not sure, and I can't really find anything specific which tends to point towards "just because." As #rayryeng points out in the comments, it could also have to do with aligning syntax with MATLAB's comma-separated lists.

Why does nothing work in my Matlab plot?

I am trying to plot with Matlab. In particular, I try with numerous online source but none of them work.
Here is my problem, I am trying to plot the expression: y=2*(x-1)/(x-4)Kb/L, and I am interested in the range of x between 0 and 1.
K=40;
b=20;
L=0.5;
x=linspace(0,1,1000);
y=2*(x-1)/(x-4)*K*b/L;
but it returns:
y=275.01
I know linspace isn't the proper way to plot. How can I plot this function? I want to keep the K,b,L declaration because I might change them latter.
y=2*(x-1)./(x-4)*K*b/L; you should use ./ replace /
Like hzy199411 said, you should use the "." operation.
I would suggest that you type "help ." at a MATLAB command prompt. MATLAB will respond with a large index of results but look for the section on "Arithmetic Operators".
You may also try the command "doc arith" but I think the "help ." is more helpful because at least in MATLAB 2013 it verbosely lists more "dot" operators.
In short several arithmetic operators prefixed with '.' ("Dot") are "Element-by-Element" operations and as such they operate on each index of the array/matrix.
For example if you had an array s=1:20 and you performed the operation s/s you would get ans = 1, where as if you did s./s you would get an array of 1's with the same length as 's'.
I guess that you are a new matlab user :). The program is in general ok, but you should think of some things. First,
linspace is not a plotting function. The function is useful though. With your syntax it creates a vector of length 1000 with range [0,1]. For plotting, type:
plot(x,y);
Linecolor and style can be set as
plot(x,y,'r-.');
For predefined colors (here 'r-.' means a red dotted line). There are also some additional properties that can be found be checking the online help of plot.
Also as the others say, if you want to operate on each element in the vector, use ./. The / is a matrix operator.

What is the equivalent to += in Matlab?

Is it possible in Matlab to increment a value of a variable without restating it on the right hand side of the statement?
AFAIK, there's no such thing in MATLAB.
And this is understandable(look at Steven Lord's answer, post 11).
That post indicates that since MATLAB is array based, such operator would be ambiguous and unintuitive, at best.
MatLab doesn't have compound assignment, but the open-source clone Octave does.
Source: http://hyperpolyglot.org/numerical-analysis

What is the # operator (at sign) in MATLAB?

I have some MATLAB programs that use the # (at sign) as an operator. What does it mean?
Does MATLAB 6.5 support this operator?
The # operator creates a function handle, something that allows you to easily create and pass around a function call like a variable. It has many nice features, none of which are available to you unfortunately. This is because as you suspect, it was not introduced into matlab until version 7, the release immediately after yours.
It used to declare Anonymous Functions in Matlab.
I think the terms is "Function Handle".
Practically it covers the inability of Matlab to declare a function at any place in any M file.
You may see it here:
What is your favourite MATLAB/Octave programming trick?
I found it to be useful in Image Processing along with the "blockproc" command.
Documentation says that it's a function handle.