Plotting a graph for a function with x <- seq(from=-2, to=2, len=10000) on the y axis and x on the x-axis

2 ビュー (過去 30 日間)
Hi there,
I'm trying to convert code in R
f<- function(x) {(sin(sin(x^2)) + cos(x/(1+x+2*x^2)) -11/10)}
x <- seq(from=-2, to=2, len=10000)
plot(x,f(x), type='l')
abline(h=0)
to code in Matlab. I've tried a few options like fplot() but it doesn't work for a sequence.
How do I achieve this?
BTW, I'm new to both R & to Matlab
  1 件のコメント
Deepti Duvvuri
Deepti Duvvuri 2020 年 9 月 23 日
Thanks so much!! Is yline the same as abline? and how do I plot a vertical abline in Matlab? Is there any documentation that I could refer to? Thank you once again!!!

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 23 日
Something like this
f = @(x) (sin(sin(x.^2))+cos(x/(1+x+2*x.^2))-11/10);
x = linspace(-2, 2, 10000);
plot(x, f(x))
yline(0);
  2 件のコメント
Steven Lord
Steven Lord 2020 年 9 月 23 日
Instead of creating your own yline to simulate the X axis, you could change where the X axis is drawn. I don't know if this is more to the original poster's liking.
ax = gca; % or call plot with an output and use ancestor
ax.XAxisLocation = 'origin';
Ameer Hamza
Ameer Hamza 2020 年 9 月 24 日
Thanks for the information, Steven.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by