What does it mean to "% extract t and h(t) for time range 5.0<=t<=12.0" when "h=4.0+6.0​*t*10^-0.5​-(4*10^-0.​25)*cos(0.​75*pi*t)"?​; when

1 view (last 30 days)
Im not really sure what this means at all...

Answers (2)

Walter Roberson
Walter Roberson on 29 Sep 2022
One way:
Loop over the indices of the vector of t. At each point, make the "current" t equal to the t vector indexed at the current index value. Test the current t to see if it is in the desired range. If it is, then save the current t and save h indexed at the current index.
At the end, the saved t will be only the t in the desired range, and the saved h will be the corresponding h elements.
This is not what I would actually do myself: I would use logical indexing.
  1 Comment
Walter Roberson
Walter Roberson on 29 Sep 2022
What the phrase means is that you need to store all the t values that are in range into a variable, and you need to store the locations in h at the corresponding offset into a variable.

Sign in to comment.


Image Analyst
Image Analyst on 29 Sep 2022
t is defined over some range, like 0 to 50 or whatever. Then the comment says they only want h values for t that is in the range 5-12. So you'd create a mask
t = linspace(0, 50, 51) % However you want it.
t = 1×51
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
h = 4.0 + 6.0 * t * 10^(-0.5) - 4 * 10^(-0.25) * cos(0.75 * pi * t)
h = 1×51
1.7506 7.4879 7.7947 8.1016 13.8388 11.8963 15.3842 18.8721 16.9296 22.6668 22.9737 23.2805 29.0178 27.0752 30.5631 34.0510 32.1085 37.8458 38.1526 38.4594 44.1967 42.2542 45.7421 49.2300 47.2874 53.0247 53.3315 53.6384 59.3756 57.4331
% Extract t and h(t) for time range 5.0<=t<=12.0"
% First make a mask
mask = (t >= 5) & (t <= 12)
mask = 1×51 logical array
0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
t2 = t(mask)
t2 = 1×8
5 6 7 8 9 10 11 12
h2 = h(mask)
h2 = 1×8
11.8963 15.3842 18.8721 16.9296 22.6668 22.9737 23.2805 29.0178

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!