Is there a more efficient way to format my vector rather than manually change the code

3 views (last 30 days)
T = 5400;
INT = 900;
tme = 0:INT:T;
TV = [tme(1):30:tme(2)-30, tme(2):15:tme(3)-15, tme(3):12:tme(4)-12, tme(4):2.4:tme(5)-2.4, tme(5):2.1428:tme(6)-2.1428, tme(6):2.5:tme(7)-2.5];
I have this code, however is there an easier way to code this if i want to change the values for 'T' and 'INT' to any random value, for the' TV' vector to automatically update rather than me manually put tme(1), tme(2) etc for those respective values in the 'tme' vector
  2 Comments
Adil Saeed
Adil Saeed on 16 Aug 2022
%Time
T = 5400;
INT = 900;
tme = 0:INT:T;
%Number of Positions and Impacts
Pn = 1320;
In = [30, 60, 75, 375, 420, 360];
TV = [tme(1):INT/In(1):tme(2)-INT/In(1), tme(2):INT/In(2):tme(3)-INT/In(2), tme(3):INT/In(3):tme(4)-INT/In(3), tme(4):INT/In(4):tme(5)-INT/In(4),...
tme(5):INT/In(5):tme(6)-INT/In(5), tme(6):INT/In(6):tme(7)-INT/In(6)];
I want to change 'T', 'INT' and 'In'. The number of values in 'In' should be equal to T/INT. So if we did change T = 5000; INT = 500; and the number of values in In = 10, these values can be random however summed should equal 'Pn', how can that 'TV' vector change automatically to cater this change or how can we combine these condition to produce the 'TV' vector

Sign in to comment.

Accepted Answer

David Hill
David Hill on 16 Aug 2022
TV =@(tme) [tme(1):30:tme(2)-30, tme(2):15:tme(3)-15, tme(3):12:tme(4)-12,...
tme(4):2.4:tme(5)-2.4, tme(5):2.1428:tme(6)-2.1428, tme(6):2.5:tme(7)-2.5];
tv1=TV(0:900:5400);
tv2=TV(0:500:5000);
  5 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!