Finding values from multiple vectors (logical indexing)

10 次查看(过去 30 天)
Hi!
I'm beginner MATLAB user. I'm stuck in a following exercise:
"The following are three vectors representing the age (years), height (cm) and weight (kg) of ten girls. A = [ 12 13 13 14 16 14 15 12 13 12]; H = [143 158 161 150 159 159 150 144 157 137]; W = [ 39 48 49 42 51 51 47 31 43 31]; a) Calculate the average of all vectors (age, height and weight). Put all three means in a column vector named mean_ahw. (Use function mean to calculate the averages.) b) How many girls in the group are taller than 150cm? Put the result in a variable named n150. c) What is the average weight of girls of age 13 or younger? Put the result in a variable named mw13. d) How many girls are taller than the average and at the same time have weight below the average? Put the result in a variable named ntall."
I did a) and b) correct but I don't know how to show the answers correctly in c) and d) when I must find values from 2 different vectors. Can someone help?
Thank you!
  2 个评论
Rik
Rik 2018-9-19
You indeed need to use logical indexing. That means you use a vector with only true/false values to select a part of another vector of the same length.
So what you need to do for c, is making a vector that contains the information about which values you should pick, then use that to select the weight, and then calculate the average.
Does that help?
Teemu Laasasenaho
Teemu Laasasenaho 2018-9-21
编辑:Teemu Laasasenaho 2018-9-21
Hi Rik,
Thank you for your answer. Now I'm getting forward !

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by