MATLAB Answers

Error using plot vectors must be the same length

2 views (last 30 days)
Dyani Peterson
Dyani Peterson on 10 Jul 2021
Commented: VBBV on 11 Jul 2021
How do I fix this error?

Answers (2)

Star Strider
Star Strider on 10 Jul 2021
It’s not easy to determine what the problem is.
One possibility is to use the gradient function instead of using diff to calculate the approximate derivative.
The outputs of gradient have the same dimensions as the input. The outputs of diff are less than the dimensions of the input.
.

VBBV
VBBV on 11 Jul 2021
V = struct2cell(velocity) % velocity is struct
VV = cell2mat(V);
A = struct2cell(acceleration) % acceleration is struct
AA = cell2mat(A)
Then use gradient function to keep the size of VV & AA same as time while plotting as suggested by @Star Strider
  1 Comment
VBBV
VBBV on 11 Jul 2021
Its good to convert struct to double array and assign it variable when plotting since you would know size of variables being plotted are same or not. In your case, size of acceleration.x and time(3:end) vectors

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by