Finding values from multiple vectors (logical indexing)

조회 수: 12 (최근 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 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