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

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));
data=fread(fid,[rows,cols],'double')
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.

Answers (1)

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)

3 Comments

B is the time..A is the data.. and Yes A(1) and A(2) has different time variations.. Im not sure i understand your Q, but it should be 1200 output lines for the data since it goes through the loop 4 times. the for loop iterates and each iteration get the file from dir and read 300 samples from it. B has the timestamp for each file.. There's no time data inside the file. I used filedir(cnt).date to get the file date of each file. Then I put them in a Array, I use datenum to convert into numbers and now I want to use it as time Vs the data. now since the data size is 1200 x 1 and the time is 4X1 iit creates an error. My goal is to plot (time,data) in a way where it would display the time every 300 samples.meaning on the coordinates of the plot would be (A(1:300), 1:00PM), (A(301:600),2:00PM), (A(601:900), 3PM) and A(901:1200), 4PM) on A(1:301)
Mini Me
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

Sign in to comment.

Products

Asked:

on 14 May 2014

Edited:

on 15 May 2014

Community Treasure Hunt

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

Start Hunting!