MATLAB Matlab plotting and defining range

AI Thread Summary
To define a variable x in MATLAB from -pi to +pi, the correct syntax is x = -pi:pi. However, an error may occur during plotting if the corresponding variable y is not defined correctly. It's essential to ensure that y is also a vector and that all operations in its definition use element-wise operators (e.g., .*, ./, .^) to allow for vector evaluation. If y is not producing a vector result, it will lead to the error message stating that the data must be numeric or convertible to double.
ketanco
Messages
15
Reaction score
0
how do you define x to be from minus pi to plus pi in matlab?

i tried:
x = -pi : piBut when i said plot (x,y)

Matlab says:

"Error using plot
Data must be numeric, datetime, duration or an array convertible to double"

(i already defined y interms of x, that function is ok)

so i culd not define x probably... how to do it?
 
Physics news on Phys.org
ketanco said:
how do you define x to be from minus pi to plus pi in matlab?

i tried:
x = -pi : piBut when i said plot (x,y)

Matlab says:

"Error using plot
Data must be numeric, datetime, duration or an array convertible to double"

(i already defined y interms of x, that function is ok)

so i culd not define x probably... how to do it?

Hi ketanco, welcome to MHB! ;)

Your x is fine, so I believe there is something wrong with your y.
Did you put a dot before each operator to allow for vector evaluation?
Did MatLab respond with a vector result for y?
 

Similar threads

Replies
8
Views
2K
Replies
5
Views
2K
Replies
4
Views
2K
Replies
1
Views
3K
Replies
3
Views
2K
Back
Top