what does mean: "@(x) ....."?

Hi everbody,
i want to understand some code, which I need for my own project.
This ist an function handle. But i can understand this:
@(x) xValue - polyval([x(1:end-1),0],yValue,[],[0,x(end)]);
What does mean x(end) or x(1:end-1) ?? How can I realize this codeline in function?
Thanks for the comming answer.

回答 (1 件)

Stephan
Stephan 2019 年 6 月 25 日
編集済み: Stephan 2019 年 6 月 25 日

1 投票

execute this code:
x = 1:10 % create a vector with elements from 1...10
a = x(end) % access last element of vector and write to a
b = x(end-1) % access 2.last element of vector and write to b
c = x(1:5) % access elements 1...5
d = x(1:end) % access all elements
e = x(1:end-1) % access all elements but not the last one
f = x(1:end-3) % access all elements but not the last three
g = x(1:2:end) % access every second element

6 件のコメント

Furkan Kocaman
Furkan Kocaman 2019 年 6 月 25 日
But this is a example with an Array in Matlab.. The question is, how can I do this steps by anaounmus function? The x in
x(1:end-1)
is from the function.. Where are the x-Values???
Stephan
Stephan 2019 年 6 月 25 日
編集済み: Stephan 2019 年 6 月 25 日
It are the x-values that are given to this function handle:
fun = @(x) 3.*x
x = 1:10
a = fun(x)
b = fun(x(1:3))
c = fun(x(end))
once you understood it for an array, you also know what it means in a function handle
Furkan Kocaman
Furkan Kocaman 2019 年 6 月 25 日
編集済み: Furkan Kocaman 2019 年 6 月 25 日
Ok, the hole line in Matlab are:
p1 = lsqnonlin(@(x) xValue-polyval([x(1:end-1), 0], yValue, [], [0, x(end)]), [p(1:end-1), mu(2)] , [], [], opts);
And now, how can I understand this??
[p(1:end-1), mu(2)] // x-values that are given to this function handle???
My goal is it to write this codeline in Python..
Walter Roberson
Walter Roberson 2019 年 6 月 25 日
Those variables would have already been assigned to before that line. Initial guess about the solution is being constructed as all except the last p vector, followed by the second mu entry. You could also phrase this like.
Temp = p ;
Temp(end) = mu(2);
and then pass Temp in place of the construct.
Furkan Kocaman
Furkan Kocaman 2019 年 6 月 25 日
Thanks.
What do Matlab / lsqnonlin with the x0 Parameter?? Matlab Help say, that is the Initial Point..
Ok, I would like to programming this in Python and use Eigen. I can pass only x- and y-Values to the LM-Solver in Eigen.. How can I create the x- and y-Values??
Walter Roberson
Walter Roberson 2019 年 6 月 25 日
Eigen for Python appears to be bindings for a C++ implementation.
The values such as zInit in the examples there correspond to x0.

サインインしてコメントする。

カテゴリ

質問済み:

2019 年 6 月 25 日

コメント済み:

2019 年 6 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by