Info

This question is closed. Reopen it to edit or answer.

Problems building a plot

1 view (last 30 days)
Lev Mihailov
Lev Mihailov on 27 Aug 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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
Adam
Adam on 27 Aug 2019
Surely you can just use a breakpoint and debug the code to see instantly what the problem is that causes the error?!

Answers (1)

Jon
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?
  6 Comments
Lev Mihailov
Lev Mihailov on 27 Aug 2019
Car='C:\CarCrarh2019.sl3';
DataCar = fopen(Car);
Data=fread(DataCar,[1,1],'uint32');
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
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.

Products

Community Treasure Hunt

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

Start Hunting!