Ramp a variable with 63 elements
4 次查看(过去 30 天)
显示 更早的评论
I have a simulink variable that has 63 elements. I would like to ramp each element in the variable proportionally from 0 to the value of the variable.
For example
A = [22 17 39 ...]
B = [0 0 0 ...]
Sample time = Ts = 1e-6
B = Ramp A
Maybe I need a toolkit that has a premade ramp block that takes an input and sets upper and lower limits.
Thanks,
David
2 个评论
Walter Roberson
2024-8-24
To check:
Do you want B to start with 0 and proceed to 22 over a fixed time, with a timestep of 1e-6? And then B should start over from 0 and proceed to 17 over a fixed time, with a timestep of 1e-6? Then B should start at 0 and proceed to 39 over a fixed time, with a timestep of 1e-6 ?
Or do you want B to start with 0 and ramp to 22 over a fixed time, with a timestep of 1e-6, followed by ramping from 22 to 17 over a fixed time with a timestep of 1e-6, then ramping from 17 to 39 over a fixed time with a timestep of 1e-6 ?
Or do you want B to become a 2D array, in which the first colum ramps from 0 to 22, the second column ramps from 0 to 17, the third column ramps from 0 to 39, all over a fixed time, so the last row would be 22 17 39 ?
回答(2 个)
Walter Roberson
2024-8-24
First option:
Use a Simulink ramp block with a vector of slopes, and with the setting of "Interpret vector parameters as 1-D" set to on (on is the default.) You might need to combine it with if/elseif and a zero-order hold block and a ramp-down block in order to get the ramp-down effect.
Second option:
Use a MATLAB Function Block with Clock as the input. Have the MATLAB Function Block implement the ramp/hold/ramp-down behaviour.
0 个评论
Sam Chak
2024-8-24
Hi @David Cole
If you do not need a smooth differentiable Ramp function, then use this math function:
where is the saturation value in the 63-element array S.
Note: The maximum saturation value in the array must be known.
S = [17, 22, 39]; % Saturation values
t = linspace(0, 0.1, 1001);
f = @(t) min(1, max(0, max(S)*t)); % Saturating Ramp function
for i = 1:numel(S)
plot(t, S(i)*f(t))
hold on
end
grid on, grid minor
xlabel('Time, t'), ylabel('f(t)')
title('Saturating Ramp function')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!