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 次查看(过去 30 天)
显示 更早的评论
Im not really sure what this means at all...
0 个评论
回答(2 个)
Walter Roberson
2022-9-29
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 个评论
Walter Roberson
2022-9-29
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.
Image Analyst
2022-9-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!