How to develop a ramp up of values into a matrix

I am trying to develop a ramp up. so i have an empty matrix named SL, and im trying to assign values to it. I want the first PnC(1), (50 values in this case) of the SL matrix to be a ramp up from 200 to 210. A ramp up being a literal ramp, so the values increase based on the gradient between 200 and 210 and the rest of the SL matrix, the values being 210.
My code and model is rather long so ive tried to include the relevant code. What i have at the moment is a steady step up (first 50 values being 200 and then >50 being 210).
%Number of Positions and Impacts
In = [50, 60, 75, 375, 420, 360];
Pn = sum(In);
PnC = cumsum(In);
%Time
T = 5400;
INT = 900;
TINT = 0:INT:T;
n = numel(TINT);
TVpieces = cell(1, n-1);
for iter = 1:n-1
Inc = INT/In(iter);
TVpieces{iter} = TINT(iter):Inc:(TINT(iter+1)-Inc);
end
TV = [TVpieces{:}];
SL = zeros(Pn,1);
for i = 1:Pn
%Source Level
if i<=PnC(1)
SL(i) = 200; %(1/90)*TVpieces{1,1} +
else
SL(i) = 210; %+ randi([-1 1]);
end
end
set(plot(TV,SL,'.'),'markersize',3)
as you can see noted out i have tried to develop the ramp up but having no success.

1 Comment

i have just editted my original post to make more sense in terms of the code, i am still unable to produce the graph i want within my code

Sign in to comment.

 Accepted Answer

n=100; PnC=50;
SL=repelem(210,1,n);
SL(1:PnC(1))=linspace(200,210,PnC(1));
plot(SL); axis padded

4 Comments

to be integrated into my code this does not work, but i will try to work around it
Matt J
Matt J on 24 Aug 2022
Edited: Matt J on 24 Aug 2022
Does this not produce the ramp shape that you intended?
it does, the graph is good, but it doesnt fit into my code due to different matrix sizes as shown above
I accepted this as I was able to use and manipulate what you did for what was needed

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 24 Aug 2022

Commented:

on 25 Aug 2022

Community Treasure Hunt

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

Start Hunting!