Does line() function works in matlab R2015b ?

5 ビュー (過去 30 日間)
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018 年 12 月 29 日
i had run code that used line() function. and then i got error in line() function.
Error using line
vectors must be the same length
Error in file_name (line 45)
line(h, [thisX, thisX], ylim(h), 'Color', 'r');
h is subplot(4, 12, 1:12).
both of thisX variables off course had the same length.
So. does MATLAB R2015B support line() function ? or was i just wrong while placing the arguments ?

採用された回答

Walter Roberson
Walter Roberson 2018 年 12 月 29 日
ylim(h) is going to be a row vector of length 2. If your thisX is not scalar then the X values you construct would not be the same length .
you cannot use line() to draw a series of vertical lines. line() can only create one line object per call. plot() can create multiple line objects per call.
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 31 日
Okay, the problem is that in R2015b, it was not yet permitted to pass an axes as the first parameter. See https://www.mathworks.com/help/releases/R2015b/matlab/ref/line.html
The cure is to use the 'Parent' parameter:
line([thisX, thisX], ylim(h1), 'Parent', h1)
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018 年 12 月 31 日
thank you very much sir @Walter Roberson ! brilliant

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

その他の回答 (2 件)

Star Strider
Star Strider 2018 年 12 月 29 日
So. does MATLAB R2015B support line() function ?
The line (link) function was ‘Introduced before R2006a’ according to the documentation, so it should.
both of thisX variables off course had the same length.
True. However you horizontally concatenated two of them.
or was i just wrong while placing the arguments ?
I would agree.
If we see your entire code, we would be able to provide more help.
  1 件のコメント
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018 年 12 月 30 日
these are my files sir. sorry for late respone

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


Jan
Jan 2018 年 12 月 29 日
"h is subplot(4, 12, 1:12)" - this is not clear. Is h a scalar or a vector?
The message is clear: [thisX, thisX] and ylim(h) do not have matching sizes. So use the debugger to examine the problem:
dbstop if error
Type this in the command window and run the code again. When Matlab stops at the error, check the sizes:
size([thisX, thisX])
size(ylim(h))
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 29 日
Watch out for thisX being row vector vs column vector. With column vector you might get away with it; with row vector you will not, not unless thisX is scalar.
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2018 年 12 月 30 日
@ Jan : this is the output of h sir: h.PNG
the size is 1x1.
And i just tried your solution sir. the error still showed up. And then output of both size([thisX, thisX]) and size(ylim(h)) are 1x2.

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by