Clear Filters
Clear Filters

I want to plot a simple graph with specific x,y coordinates. I can plot when the y values are integers. But i need to plot values like 9/4. this is my error code Attempted to access y(2.25); index must be a positive integer or logical.

57 views (last 30 days)
i want to plot the points (0,2) (1,9/4) (2,38/17) (3,161/72) (4,682/305)

Accepted Answer

Niels
Niels on 25 Jan 2017
plot([0 1 2 3 4],[2 9/4 38/17 161/72 682/305])
  3 Comments
JJ
JJ on 25 Jan 2017
Thanks, i cant believe i was trying to make it so complicated. Do you know if you can extend the decimal value on the graph? I have changed to format long, on the screen the decimals haven changed but the graph is still rounding them, i wanted to show the values converging to sqrt(5)
Niels
Niels on 25 Jan 2017
you can change the YAxes Tick but it seems like you are not familiar with structur arrays nor properties of anything, so it will be hard for you. if you want to have more decimals on your y axes you have to acces the axes-properties .YTick:
>> h=plot(x,y,'.--');
>> h.Parent.YTick=[linspace(2,2.2,3),linspace(2.21,2.25,6)];

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots 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!