# Error using ==> plot Vectors must be the same lengths.

1 view (last 30 days)
Mini Me on 14 May 2014
Edited: Mini Me on 15 May 2014
What if you have two vectors. let's say A size is 1200 x 1 and B size is 4 x 1... B is timestamp of each file processed in a directory.. meaning each file has 300 samples in it i.e 1200/4 gives you only 4 diff timestamps. what if i want plot(B,A) for that the timestamp would display every 300 samples on the x axis. of course when i tried to do it with my code i get this error: Error using ==> plot Vectors must be the same lengths.
filedir = dir(dirpath)
timerArray=[];
Array=[];
for cnt=1:length(filedir)
timerArray=vertcat(timerArray, (filedir(cnt).datenum));
Array=horzcat(Array, data);
plot(timerArray,Ex)
datetick('x' , 13 , 'keeplimits')
end
part of the code if there are errors it might because i was cropping the most relevant part of the code for the question.

Walter Roberson on 14 May 2014
How many output lines are expected? 1 or 4 or 300?
Is A(2) to be considered to be at a different time than A(1)? If so then are the times for A(1:301) to be equally distributed over the time range between B(1) and B(2)? And A(301:601) times to b equally distributed over the time range B(2) to B(3) ? If so then what is the final time for A(1200) as there is no B(5) to know the interpolation?
Or is there a fixed interval between A(1) and A(2) that is the same as the interval between A(301) and A(302)? Is the time associated with A(300) by the fixed interval potentially more than one tick before B(2) [leaving a gap] or potentially after B(2) [making an overlap] or is B(2) certain to be exactly right to be one tick after the time associated with A(300)?
Could it be that there is a continuous time base like above, and the times in B are merely the times you want to be specifically labelled ?
If that is the case, that B tells you where to label, then you need to create a time vector, T, giving the time associated with each element of A, and then you
plot(T, A);
set(gca, 'XTick', B)
Mini Me on 15 May 2014
Edited: Mini Me on 15 May 2014
Why does A need to be reshape?and i tried it, it didnt work. The date now is displaying the way i want it to, but the plot is wrong. Im still looking into that. what happen now is that when I reshape A to 300 X 4. each time I plot it against B every 300 points it restaart at the 0 point. I wanted A(1:300) to start at B(1), A(301:600) to start at B(2) and so on

### Categories

Find more on Annotations 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!