Error using ==> plot Vectors must be the same lengths.
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Walter Roberson
2014-5-14
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 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!