# 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)

Show older comments

Im not really sure what this means at all...

##### 0 Comments

### Answers (2)

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
on 29 Sep 2022

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.

h = 4.0 + 6.0 * t * 10^(-0.5) - 4 * 10^(-0.25) * cos(0.75 * pi * t)

% Extract t and h(t) for time range 5.0<=t<=12.0"

% First make a mask

mask = (t >= 5) & (t <= 12)

t2 = t(mask)

h2 = h(mask)

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!