Error adding a line to an axes

1 次查看(过去 30 天)
Hi,
I am trying to add a line to a GUI axes. The line function works from the command window, but throws an error when executing it from the GUI. The error I receive is "Vectors must be the same length." Thanks in advance!
%example of line from command window
line([10,10],[0,10],'color','black');
%example of code from GUI.m file
time = VideoObj.currentTime;
y = ylim(handles.axesGraph);
line(handles.axesGraph, [time,time], y, 'color', 'black');
  2 个评论
dpb
dpb 2017-12-1
The conclusion must be one or the other--either time isn't a scalar or y isn't a 2-vector (maybe is empty?).
Set a breakpoint in the debugger and see what isn't as expected inside the routine.
Andrew Vallejos
Andrew Vallejos 2017-12-1
编辑:Andrew Vallejos 2017-12-4
Time is a numeric scalar, per the docs. https://www.mathworks.com/help/matlab/ref/videoreader.html
ylim returns a vector of size two, per the docs. https://www.mathworks.com/help/matlab/ref/ylim.html?searchHighlight=ylim&s_tid=doc_srchtitle#buob5nn-1
I have also done the due diligence of dumping both variable to ensure that the values are what I expect. For example, my first frame has the following values: time = [0.633, 0.633] y = [0, 14]
Thanks!

请先登录,再进行评论。

采纳的回答

Andrew Vallejos
Andrew Vallejos 2017-12-4
I figured out the problem. The error is that I am using an older version of MATLAB, that does not support the function as I am attempting to use it. Thanks for everyone's help.

更多回答(1 个)

Jan
Jan 2017-12-2
编辑:Jan 2017-12-2
Use the debugger to identify the problem:
dbstop if error
Now let the code run again. If it stops at the error, examine the used variables again:
size(time)
class(time)
size(y)
class(y)
Maybe handles.axesGraph is not a single axes handle?
  3 个评论
Jan
Jan 2017-12-4
编辑:Jan 2017-12-4
What is a "numeric"? I still cannot follow your explanations. Please be so kind and copy&paste the output of:
size(time)
class(time)
size(y)
class(y)
when Matlab stops at the error. Then please post a copy of the complete error message also. If I understand it correctly, the message contains the detail, that in the command
line(handles.axesGraph, [time,time], y, 'color', 'black');
the sizes of "[time, time]" and "y" differ. If they do not differ, the problem must be somewhere else. Then execute the command in parts in the command window during the debugging:
line([time,time], y);
Does this work? If so, try:
line(handles.axesGraph, [time,time], y);
line([time,time], y, 'color', 'black');
What is required to produce the error message? Simply play with this command to find out, where the problem is. This is called "debugging" and it is more efficient than letting the members of the forum try to debug your code remotely by suggesting commands - most of all if you post a rephrased output only.
Matlab is not sensitive. You can squeeze it and punch it with wrong commands, but this will not change its mood. Matlab will remain willing to tell you as much as it knows about the problems. So use its assistance directly.
Andrew Vallejos
Andrew Vallejos 2017-12-4
Sorry, I meant double. My other programming languages are coming out. :) I will try your other recommendations. The vectors I am passing are the same size. I have tried to make it more explicit below. Sorry for the confusion.
size(y)
%returns ans = [1 2].
size([time time])
%returns ans = [1 2].
size(time)
%returns ans = [1 1].

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by