Finding values from multiple vectors (logical indexing)

2 views (last 30 days)
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 Comments
Rik
Rik on 19 Sep 2018
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 on 21 Sep 2018
Edited: Teemu Laasasenaho on 21 Sep 2018
Hi Rik,
Thank you for your answer. Now I'm getting forward !

Sign in to comment.

Answers (0)

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!