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.

 採用された回答

Niels
Niels 2017 年 1 月 25 日
plot([0 1 2 3 4],[2 9/4 38/17 161/72 682/305])

3 件のコメント

Niels
Niels 2017 年 1 月 25 日
編集済み: Niels 2017 年 1 月 25 日
you should save the x values in 1 variable and the y values into another one:
x=[0 1 2 3 4];
y=[2 9/4 38/17 161/72 682/305];
then plot:
plot(x,y)
to learn more abour plot look here
example:
% change color to red, markers are set to diamonds, and dashed linestyle
plot(x,y,'rd--')
JJ
JJ 2017 年 1 月 25 日
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)
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)];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

JJ
2017 年 1 月 25 日

コメント済み:

2017 年 1 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by