Why is @(x) used in matlab and how does it work?
Show older comments
pdfx = @(x) 2*sqrt(x); % Define PDF
x = rand(1,100000); % Generate Random ‘x’
px = pdfx(x); % Generate Data
This is a piece of code used to generate a random variable of self defined pdf. Why is @(x) used here and how is it working.
Accepted Answer
More Answers (1)
madhan ravi
on 11 May 2020
Edited: madhan ravi
on 11 May 2020
0 votes
It’s just a matter of choice as Kalyan mentioned above how it works. The usage depends completely on the coder. As pdfx(...) was defined before generation of data , it was defined as a function handle here. It’s equivalent to pdfx = ... without @(x) after generation of x.
3 Comments
KALYAN ACHARJYA
on 11 May 2020
OK Thanks
madhan ravi
on 11 May 2020
I meant to say
pdfx = 2*sqrt(x)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!