What is the equivalent to += in Matlab? - 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

Related

how to convert this result using exponentials to hyperbolic trig functions?

The solution to Laplace PDE on rectangle is usually written using hyperbolic trig functions. I solve this PDE using Maple. Verified Maple solution is correct. But having hard time figuring how to make its result match the book result.
I tried sol:=convert(rhs(sol),trigh): then simplify(sol,trig); and it become little closer to the book solution, but is still can be more simplified.
Are there any tricks to do this?
Here is MWE
restart;
interface(showassumed=0):
pde:=diff(u(x,y),x$2)+diff(u(x,y),y$2)=0:
bc:=u(0,y)=0,u(a,y)=f(y),u(x,0)=0,u(x,b)=0:
sol:=pdsolve([pde,bc],u(x,y)) assuming(0<=x and x<=a and 0<=y and y<=b):
sol:=subs(infinity=20,sol);
Which gives
The above is same as the following, which I am trying to convert the above to
textbookU:= Sum(2*sin(n*Pi*y/b)*(Int(sin(n*Pi*y/b)*f(y),
y = 0 .. b))*sinh(n*Pi*x/b)/(b*sinh(n*Pi*a/b)), n = 1 .. 20);
The above are the same. I checked few points, and they give same answer. They must be the same, as the above textbook solution is correct, and I am assuming Maple solution is correct.
Now I tried to convert Maple sol to the above as follows
sol:=convert(rhs(sol),trigh):
simplify(sol,trig);
May be someone knows a better way to obtain the textbook solution form, starting from the Maple solution above.
Using Maple 2017.3 on windows
After the convert you can first expand it, to then simplify it again:
s := convert(sol, trigh):
s := expand(s):
simplify(s);
which gives:

Is there a GNU Octave equivalent for the Matlab function "fit"?

My teacher in the signal analysis course has given me some Matlab code that I have to execute in order to complete a home assignment. I have always been using GNU Octave without troubles, but this time there is this command that is giving me headaches.
[c8,g8]=fit(time, sin_4_harmonic,’fourier8’)
I cannot find the function "fit" in GNU Octave, which is referenced for Matlab at the following url http://www.mathworks.se/help/curvefit/fit.html
Does anyone knows which package should I load, or if there is any equivalent?
Thanks =)
As far as I know, that function is not present in any of the Octave packages. However, the best place to look for something similar would be the optim package, probably the function nonlin_curvefit. Looking at the documentation, the model fourier8 is of the type Y = a0+a1*cos(x*p)+b1*sin(x*p)... +a8*cos(8*x*p)+b8*sin(8*x*p).
A work-around may be using "polyfit" function. To get the values, use "polyval".

What is Matlab's colon operator called?

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 ...

How to use find() method in simulink?

I have to translate the .m file to simulink but I don't have any idea about How to use find() method. The result of the find() method is variable vector, which is not allowed by the simulink. Does anybody can help? Thanks.
You can try using a matlab function block (or maybe a prelookup might work, depending on the application).
Use:
[index]=find(data,1)
The second parameter of find specifies how many indices you want to find. Now find outputs a constant length vector and can be used in simulink.
Perhaps you can do this with the Submatrix or Selector blocks. This answer may be helpful.

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.