x= linspace(0,6*180,1000);
y1 = sind(x);
y2 = sind(x-120);
y3 = sind(x-240);
plot(x,y1,x,y2,x,y3)
ax = gca;
ax.XLim = [0 4*180]
ax.XTick = [0 180 2*180 3*180 4*180]
ax.XAxisLocation = 'origin';
THIS CODE IS NOT WORKING

5 件のコメント

Adam
Adam 2018 年 2 月 14 日
There's no point just saying something is 'not working' if you don't explain why. Both axes in that plot appear to be at the origin to me when I run the code.
Jos (10584)
Jos (10584) 2018 年 2 月 14 日
When I execute your code above in R2017b, I get the following error:
Undefined function or variable 'THIS'.
Jan
Jan 2018 年 2 月 14 日
@Jos: Did you copy and paste "THIS CODE IS NOT WORKING" also?
Ankit kumar
Ankit kumar 2018 年 2 月 14 日
No.
Jos (10584)
Jos (10584) 2018 年 2 月 14 日
@jan: yep :p (silly joke, I'll admit it ...)

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

 採用された回答

Steven Lord
Steven Lord 2018 年 2 月 14 日

0 投票

If the error you receive is that 'origin' is not a valid or recognized value for the XAxisLocation property, you may be using a release older than release R2015b which is when that value was added as an option for the XAxisLocation property. Prior to that the only allowed options were 'top' and 'bottom'.
If you received a different error, or did not receive an error but did not receive the behavior you expected, tell us what release you're using and describe in detail (including any error or warning messages you received, all the text in red or orange) what happened.
One more point: I would be careful about using gca in my code. A user of that code, clicking on a different axes in a different figure between the plot call and the line that creates the variable ax, could change what the current axes is and so make gca return something other than what you expect.

2 件のコメント

Ankit kumar
Ankit kumar 2018 年 2 月 14 日
編集済み: Ankit kumar 2018 年 2 月 14 日
I am using R2015 version.My code is working fine but only x axis is not shifted to origin.
Steven Lord
Steven Lord 2018 年 2 月 14 日
Use print to print the figure window to an image file then insert that image into a comment on this question using the button that looks like a green object inside a brown frame.

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by