Matlab plotting and defining range

Click For Summary
SUMMARY

The discussion centers on defining a range for the variable x in MATLAB, specifically from -π to +π. The user encountered an error when attempting to plot, indicating that the data must be numeric or convertible to double. The solution involves ensuring that the y variable is defined correctly in relation to x, particularly by using element-wise operations with a dot before each operator to enable vector evaluation. This approach resolves the plotting issue in MATLAB.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with vectorization in MATLAB
  • Knowledge of plotting functions in MATLAB
  • Basic understanding of mathematical functions and their implementation in MATLAB
NEXT STEPS
  • Learn about MATLAB vectorization techniques
  • Explore MATLAB plotting functions and their requirements
  • Investigate the use of element-wise operations in MATLAB
  • Study error handling in MATLAB plotting
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in mathematical modeling, data visualization, and anyone troubleshooting plotting errors in MATLAB.

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 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K