Plot with linspace: display x-tick values not index

  • Thread starter Thread starter skynelson
  • Start date Start date
  • Tags Tags
    Index Plot
AI Thread Summary
The discussion centers on modifying the x-axis of a MATLAB graph to display tick values from 0 to 1 instead of the default index range from 1 to 1000. The user is working with data generated by linspace, which creates a vector W ranging from 0 to 1. To achieve the desired x-axis labeling, a solution is provided that involves including the vector W in the plot command. The suggested code snippet allows for precise control over the x-axis ticks and labels, enabling the user to customize the graph to resemble a physics graph. The exchange highlights the effectiveness of MATLAB's syntax for achieving specific plotting requirements.
skynelson
Messages
57
Reaction score
4
I want my graph to display the tick values along the x-axis, instead of the index number.
Because I use linspace, my data goes from 0 to 1, but my index ranges from 1 to 1000.
My plot labels the x-axis from 1 to 1000, by default. I want to change the default (or just program it) to display 0 to 1, so it looks like a physics graph. Any help much appreciated, thanks!
Code:
T = 4;
W = linspace(0, 1, 1000);
plot(sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

labelsXaxisExample.jpg
 
Physics news on Phys.org
This looks like Matlab to me - is that correct? If so, you just include the vector W insdied the plot command

plot(W, sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

jason
 
Code:
A = plot(sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

A.Parent.XTick = [0:100:1000];
A.Parent.XTickLabel = {'0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1'};

1610980510344.png
 
  • Like
Likes skynelson
jasonRF said:
This looks like Matlab to me - is that correct? If so, you just include the vector W insdied the plot command

plot(W, sin(T*2*pi*W+1E-8)./(2*pi*W + 1E-8));

jason
Yes, That's it! And yes, MATLAB. I figured there was a straightforward syntactical approach. Thanks Jason.
 
Thanks hdp12 for the response! This is a good approach for more specific control over layout.
 
  • Like
Likes hdp12

Similar threads

Replies
1
Views
2K
Replies
10
Views
3K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top