2 views (last 30 days)

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) ???

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

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.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/477736-problems-building-a-plot#comment_739415

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/477736-problems-building-a-plot#comment_739415

Sign in to comment.