Error adding a line to an axes

1 view (last 30 days)
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
%example of code from GUI.m file
time = VideoObj.currentTime;
y = ylim(handles.axesGraph);
line(handles.axesGraph, [time,time], y, 'color', 'black');
Andrew Vallejos
Andrew Vallejos on 1 Dec 2017
Edited: Andrew Vallejos on 4 Dec 2017
Time is a numeric scalar, per the docs.
ylim returns a vector of size two, per the docs.
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]

Sign in to comment.

Accepted Answer

Andrew Vallejos
Andrew Vallejos on 4 Dec 2017
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.

More Answers (1)

Jan on 2 Dec 2017
Edited: Jan on 2 Dec 2017
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:
Maybe handles.axesGraph is not a single axes handle?
Andrew Vallejos
Andrew Vallejos on 4 Dec 2017
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.
%returns ans = [1 2].
size([time time])
%returns ans = [1 2].
%returns ans = [1 1].

Sign in to comment.


Find more on Migrate GUIDE Apps in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by