Borrar filtros
Borrar filtros

how do I extend my function on the time axis by the function value of 0 ?

2 visualizaciones (últimos 30 días)
enrico Rothe
enrico Rothe el 14 de Mzo. de 2022
Comentada: Jan el 15 de Mzo. de 2022
Hey guys i m new to matlab and i need help,
i generated a acceleration function for a simulink model. to make it work i have to increase the time axes to tFinal =10 sec but the acceleration must be 0 . the original function goes to t= 3.677s. Here the acceleration is alomost 0.
I thought i ll use a for loop to increase the time axis but it ist not working. can someone help me ?
%Fourierkoeffizienten eigenes Model
sk=[0.0 -0.00850314 0.0 0.00377249 0.0 -0.000182763 0.0 0.000029564 0.0000652721 0.000052017];
ck=[0.0240577 -0.0241291 0.0 -0.00210694 0.00208514 -0.00044844 0.000515647 -0.0000502304 0.000126237 -0.0000402195];
%Taktzeit in s
tT = 3/5*2*pi;
%Übertragungsfaktor phi = omega * t mit Omega in rad/s
omega = (1/tT)*2*pi;
%Zeitvektor für neues Signal
t_mHsl = linspace(0,tT,1000);
%Bestimmung des Beschleunigungsvorgabe
s_mhsl = zeros(length(1),length(t_mHsl));
v_mhsl = zeros(length(1),length(t_mHsl));
a_mhsl = zeros(length(1),length(t_mHsl));
for k = 0:length(sk)-1
%Wegvorgabe
p = 0;
s_mhsl = s_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 1;
v_mhsl = v_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 2;
a_mhsl = a_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
end
% plot Beschl.Verl nach Erzeugung der Bewegungsvorgabe mit mHsl
mhsl.time = t_mHsl;
mhsl.a = a_mhsl;
% Beschl.
figure()
plot(mhsl.time,mhsl.a)
% Beschl.verlauf Errerfunktion verlängert von tT auf tFinal
t_mHsl_tFinal = linspace(0,tFinal,1000);
BeschlmHsl = zeros(length(1),length(t_mHsl_tFinal));
for i = 1:length(t_Final)
if t_mHsl_tFinal(i)<=t_mHsl(end) % endwert der Erregerfunktion für tT = 3/5 *2pi
BeschlmHsl(i) = a_mhsl(1,:);
else
BschlmHsl(i) =0;
end
end
figure()
plot(t_Final,BschlmHsl);
  2 comentarios
Jan
Jan el 14 de Mzo. de 2022
I've formatted your code. Please use the tools on top of the editing field. Thanks.
length(1) determines the number of elements of a scalar. It is easier to write "1" directly:
s_mhsl = zeros(1, numel(t_mHsl));
The command length is fragile, because it determines the longest dimension. This does, what you expect, for vectors. But for arrays it is a frequent cause of bugs. Use size(X, dim) or numel(X) instead.
What does this mean: "I thought i ll use a for loop to increase the time axis"?
The statement "but it ist not working" is less clear than a description of what you observe.
enrico Rothe
enrico Rothe el 14 de Mzo. de 2022
thanks a lot for the help!
sk=[0.0 -0.00850314 0.0 0.00377249 0.0 -0.000182763 0.0 0.000029564 0.0000652721 0.000052017];
ck=[0.0240577 -0.0241291 0.0 -0.00210694 0.00208514 -0.00044844 0.000515647 -0.0000502304 0.000126237 -0.0000402195];
%Taktzeit in s
tT = 3/5*2*pi;
%Übertragungsfaktor phi = omega * t mit Omega in rad/s
omega = (1/tT)*2*pi;
%Zeitvektor für neues Signal
t_mHsl = linspace(0,tT,1000);
%Bestimmung des Beschleunigungsvorgabe
s_mhsl = zeros(length(1),length(t_mHsl));
v_mhsl = zeros(length(1),length(t_mHsl));
a_mhsl = zeros(length(1),length(t_mHsl));
for k = 0:length(sk)-1
%Wegvorgabe
p = 0;
s_mhsl = s_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 1;
v_mhsl = v_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 2;
a_mhsl = a_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
end
% plot Beschl.Verl nach Erzeugung der Bewegungsvorgabe mit mHsl
mhsl.time = t_mHsl;
mhsl.a = a_mhsl;
% Beschl.
figure()
plot(mhsl.time,mhsl.a)
% Beschl.verlauf Errerfunktion verlängert von tT auf tFinal
t_mHsl_tFinal = linspace(0,tFinal,1000);
BeschlmHsl = zeros(1,numel(t_mHsl_tFinal));
for i = 1:numel(t_mHsl_tFinal)
if t_mHsl_tFinal(i)<=t_mHsl(end) % endwert der Erregerfunktion für tT = 3/5 *2pi
BeschlmHsl(1,i) = a_mhsl(1,:);
else
BeschlmHsl(1,i) =a_mhsl(1,:);
end
end
figure()
plot(t_Final,BeschlmHsl);
What does this mean: "I thought i ll use a for loop to increase the time axis"?
i m able to plot my acceleration function for the timevector t_mHsl. (t_mHsl final value = 3.66..sec) to use it in my simulink model i have to expent the acceleration function to t=10 sec but the acceleration values must be 0 after t = 3.66 sec.. and i thought i can solve it with a for loop ?
if i run the code now i still get the error Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-1000.
for BeschlmHsl(1,i) = a_mhsl(1,:);

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 14 de Mzo. de 2022
Editada: Jan el 14 de Mzo. de 2022
I'm not sure, what the purpose of the loop is, but this is not a loop at all:
for i = 1:length(t_Final)
If t_Final is 10, as you explain in the text, length(t_Final) is 1. Then the loop runs from 1 to 1.
Maybe you mean:
for i = 1:numel(t_mHsl_tFinal)
You have pre-allocated BeschlmHsl to zeros already. Then there is no reason to write 0 into the values again. Omit:
else
BschlmHsl(i) =0;
This cannot work:
BeschlmHsl(i) = a_mhsl(1,:);
There is a scalar on the left and a vector on the right.
  3 comentarios
enrico Rothe
enrico Rothe el 14 de Mzo. de 2022
i got i working now but the acceleration curve doesent look like i need it :D i m not sure if i can solve my problem with one for loop. i might have to put my two for loops together the get the result i want ?
i you copy the code to matlab u get 2 figures. i need the curve of the first figure and after t => 3.766 the acceleration curve must be 0 ^^^
sk=[0.0 -0.00850314 0.0 0.00377249 0.0 -0.000182763 0.0 0.000029564 0.0000652721 0.000052017];
ck=[0.0240577 -0.0241291 0.0 -0.00210694 0.00208514 -0.00044844 0.000515647 -0.0000502304 0.000126237 -0.0000402195];
%Taktzeit in s
tT = 3/5*2*pi;
%Übertragungsfaktor phi = omega * t mit Omega in rad/s
omega = (1/tT)*2*pi;
%Zeitvektor für neues Signal
t_mHsl = linspace(0,tT,1000);
%Bestimmung des Beschleunigungsvorgabe
s_mhsl = zeros(1,length(t_mHsl));
v_mhsl = zeros(1,length(t_mHsl));
a_mhsl = zeros(1,length(t_mHsl));
for k = 0:length(sk)-1
%Wegvorgabe
p = 0;
s_mhsl = s_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 1;
v_mhsl = v_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
%Beschleunigungsvorgabe
p = 2;
a_mhsl = a_mhsl + (k^p*omega^p*(ck(k+1)*cos(p*pi/2+k*omega*t_mHsl)+sk(k+1)*sin(p*pi/2+k*omega*t_mHsl)));
end
% plot Beschl.Verl nach Erzeugung der Bewegungsvorgabe mit mHsl
mhsl.time = t_mHsl;
mhsl.a = a_mhsl;
% Beschl.
figure()
plot(mhsl.time,mhsl.a)
% Beschl.verlauf Errerfunktion verlängert von tT auf tFinal
t_mHsl_tFinal = linspace(0,tFinal,1000);
BeschlmHsl = zeros(1,numel(t_mHsl_tFinal));
for i = 1:numel(t_mHsl_tFinal)
if t_mHsl_tFinal(i) <= t_mHsl(end) % endwert der Erregerfunktion für tT = 3/5 *2pi
BeschlmHsl(i) = a_mhsl(1,1000);
else
BeschlmHsl(i) =0;
end
end
figure()
plot(t_Final,BeschlmHsl);
Jan
Jan el 15 de Mzo. de 2022
I have mentioned, that I have formatted the code for you in the question. Please apply a proper formatting by your own to improve the readaility of the code. Thanks.
"i need the curve of the first figure and after t => 3.766 the acceleration curve must be 0" - please consider, that the reader cannot guess, which variable is meant. While this detail is obvious for you, it is a puzzle for the readers.
Maybe you mean:
t_mHsl_tFinal = linspace(0, tFinal, 1000);
BeschlmHsl = zeros(1, numel(t_mHsl_tFinal));
index = t_mHsl_tFinal < t_mHsl(end);
BeschlmHsl(index) = a_mhsl(1, 1000);
No loop needed.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by