When I ran your code, I got the same error. I tracked it down to your use of ‘spring’ as a variable name, as well as noting that in your ‘fres’ assignments that use it, you did not initially capitalise it.. This is actually the name of a colormap, so was creating a (64x3) matrix for your variable, and that was throwing the error. I corrected it to ‘Spring’ everywhere, and still got the error. What I find interesting is that as a general rule, MATLAB is case-sensitive, so ‘Spring’ and ‘spring’ should not be the same. (I am running this on R2019a.) I finally changed it to ‘SpringK’ everywhere, and the error disappeared.
The changes are:
and:
if u(i-2) <= 0 && u(i-1) >= 0
fres = (mass*g*(sind(angle)) - (staticf*cosd(angle)));
elseif (u(i-2) >= 0 && u(i-1) >= 0 && displacement_data(i-1) < Initial) || (u(i-2) < 0 && u(i-1) < 0 && displacement_data(i-1) < Initial)
fres = mass*g*(sind(angle) + multiplier*(dynamicf*cosd(angle)));
elseif u(i-2) >= 0 && u(i-1) <= 0
fres = mass*g*(sind(angle) + staticf*cosd(angle)) - SpringK*(displacement_data(i-1) - Initial);
elseif u(i-2) >=0 && u(i-1) >= 0 && displacement_data(i-1) >= Initial || u(i-2) < 0 && u(i-1) < 0 && displacement_data(i-1) >= Initial
fres = mass*g*(sind(angle) + multiplier*(dynamicf*cosd(angle))) - SpringK*(displacement_data(i-1) - Initial);
end
We are left with one error:
Undefined function or variable 'acceleration_data'.
fprintf('%.4f\t\t%.4f\t\t%.4f\t\t%.4f\n', displacement_data(i-1), acceleration_data(i-1),
time_data(i), u(i-1));
I defer to you to solve that.
Best Answer