Error using plot Vectors must be the same length.
1 次查看(过去 30 天)
显示 更早的评论
I am trying to plot this.
plot(time,cellvoltages).
Size of cellvoltages is 36004 x 84.
That is fixed. Now the time varies according what we give. So Time is found out using a series of lines of code.
time_sec = (1:len_dataset)*dt;
time = time_sec/3600;
len_dataset is 36004. That is fixed. dt is what we give. So if we give dt as something less than 1 for eg 0.5 then plot works perfectly. The size of time in that case is 1 x 501. But if we give dt more than 1 say 1.25 then its giving an error
Error using plot
Vectors must be the same length.
This size of time now is 1 x 28800.
What is the cause of this error. Can anyone help me. Thank you.
6 个评论
Dyuman Joshi
2023-8-16
[index_min, index_max] = find_time_index(time, TIME_MIN, TIME_MAX);
if index_min < 1
index_min = 1;
end
time = time(index_min:index_max);
This snippet of code does not make sense to me.
Maybe you can attach the part of the code that is relevant to the problem you are facing.
Without the working code, it is difficult to suggest anything.
回答(1 个)
Steven Lord
2023-8-16
You can create a vector in MATLAB using any three of the four pieces of data starting point, ending point, space between points, and number of points. In this case you're using the first three of those pieces of data but then the number of points may not be what you want. In that case I'd use the starting and ending points and the desired number of points instead
Define data
startpoint = 1;
endpoint = 10;
spacing = 0.5;
numpoints = 19;
Start, end, space
A1 = startpoint:spacing:endpoint
Start, end, number
A2 = linspace(startpoint, endpoint, numpoints)
Start, spacing, number
A3 = startpoint + spacing*(0:numpoints-1)
End, spacing, number
A4 = -spacing*flip(0:numpoints-1) + endpoint % Work backwards
Check
isequal(A1, A2, A3, A4)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Feature Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!