Vectors as input and output in a function
Show older comments
I am calling this function in another script. The function is called 'a.m' and is in the same folder as the script. aceleracion should be an output vector and u is an input vector. I am getting the following error:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in a (line 11)
aceleracion(indtiempo)=h*w*cos(w*u(indtiempo)-pi);
Error in Encoder_interpolacion_lineal_online_y_offline_con_aceleracion (line 319)
aang=a(taang);
Thanks in advance.
function [aceleracion] = a(u)
global periodo;
global h;
global w;
for indtiempo=1:length(u)
if u(indtiempo)<=periodo/2
aceleracion(indtiempo)=h*w*cos(w*u(indtiempo));
else
aceleracion(indtiempo)=h*w*cos(w*u(indtiempo)-pi);
end
end
end
2 Comments
Walter Roberson
on 28 May 2021
Put a breakpoint in at the for loop. When the code stops, examine
size(periodo)
size(h)
size(w)
size(w)
Luciano Montanelli
on 28 May 2021
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!