# Problems building a plot

2 views (last 30 days)
Lev Mihailov on 27 Aug 2019
Commented: Jon on 27 Aug 2019
Data 100x10 Data(1,1)=[10 20 10 10 10 30 20 .... ] % my meanings
x1 1x10 % value coordinates
x2 1x10
z % coefficient for recalculation of coordinates during
timezone=x1*z % 1x10
timeline 100x1 timeline =[1 2 3 4 ...] % time values
plot(Data,timeline)
%% so my schedule goes blank
plot(Data,timeline)
hold on
plot(Data(x1:x2),timeline,'o-g')
hold off
Error using plot
Vectors must be the same length.
Error in CarProblem1 (line 3
Hello! I need to plot the data metrics against time
1) How can I fix a mistake in paragraph 3 ?
2) when building plot (Data, timeline), my graph looks something like this (by date 40, and by time 100), is it possible, for convenience, to write my time in minutes (there is a conversion factor) ???

#### 1 Comment

Surely you can just use a breakpoint and debug the code to see instantly what the problem is that causes the error?!

Jon on 27 Aug 2019
Edited: Jon on 27 Aug 2019
In general the error you are getting is telling you that if you want to plot one variable against another they both have to have the same number of elements, and yours do not have the same number of elements
Please supply your actual code where you define x1, x2, Data and timeline and we might be able to get a better idea of where things are going wrong.
Regarding your question about having the time display in minutes. When plotting with time as the x axis you can define the "x" variable as a MATLAB datetime array and it handles the scaling and so on nicely.
By the way, I notice in your code that you have Data as the first argument to plot and timeline as the second argument. This will put timeline as the vertical axis in your plot. Is this what you want?

Jon on 27 Aug 2019
Sorry I don't have that file, so that still doesn't allow me to replicate the error. As @Adam suggests, you should try stepping through the code using the debugging tool and maybe you can see for yourself where things are going wrong. If you haven't already been using the debugging tools I definitely recommend that you learn about this. Here's some documentationhttps://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
Lev Mihailov on 27 Aug 2019
Car='C:\CarCrarh2019.sl3';
DataCar = fopen(Car);
z=0.59
timezone=x1*z % 1x10
timeline 100x1 timeline =[1 2 3 4 ...] % time values
plot(Data,timeline)
plot(Data,timeline)
hold on
plot(x1:x2,Data(x1:x2),timeline,'o-g')
hold off
Error using plot
Data must be a single matrix Y or a list of pairs X,Y.
when using the debugger
Error using plot
Vectors must be the same length.
I certainly understand that I'm trying to use different sizes, but x1 and x2 are the coordinates of my data
Jon on 27 Aug 2019
Now you have another problem. When you call plot you must have pairs of x and y so for example
plot(x1,y1,x2,y2)
You have one x,y pair x1:x2, Data(x1:x2) followed by just a single entry timeline.