Finding values from multiple vectors (logical indexing)

4 ビュー (過去 30 日間)
Teemu Laasasenaho
Teemu Laasasenaho 2018 年 9 月 19 日
編集済み: Teemu Laasasenaho 2018 年 9 月 21 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by