Can't plot a function : Error using plot Invalid data argument.

Mathworks_doubt.JPG
So, I was trying to plot as a function of ϕ when I know that ϕ will lie from 0 to 1.
My code follows like this:
x = linspace(0,1);
y = @(x) (4.63 + (0.3./(x*exp(x.^2)*erfc(x))));
plot(x,y)
The error I get is:
--------------------------------
Error using plot
Invalid data argument.
Error in Matlab_Code_Assignment (line 3)
plot(x,y)
--------------------------------
What was the mistake I was doing ?

5 Comments

You didn't pass an argument to your anonymous function, y. Try
plot(x,y(x))
Then, you'll get to find all the places you're also still missing "dot" operators in y.... :)
x = linspace(0,1);
y = @(x) (4.63 + (0.3/(x.*exp(x.^2)*erfc(x))));
plot(x,y(x))
Now, this shows the error:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use '.*'.
Ayup...that's what I told you was going to happen... :)
Follow the hint in the help...
ok. I have used other method. Just remove the dots and @ sybmol. Works fine as it creates a y vector with size same as x vector. It works fine now.
Wrong approach...fix the anonymous function to use all dot operators.

Sign in to comment.

Answers (0)

Products

Tags

Asked:

on 6 Mar 2019

Commented:

dpb
on 6 Mar 2019

Community Treasure Hunt

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

Start Hunting!