필터 지우기
필터 지우기

How to use one data set to find the mean of another?

조회 수: 2 (최근 30일)
Kristin Aldridge
Kristin Aldridge 2021년 8월 31일
댓글: Kristin Aldridge 2021년 9월 1일
I have a data set (neighbors) and a data set (height) where I need to find the mean of the height of the plants that have 1 neighbor.
If say my Neighbors data set is 2,1,4,1,6,7,3,1 and my height is 12.5,17,10,4,16,20.4,13.2,9.4 . How do I compare these two? My thought is to use NON=find(Neighbors==1) and somehow use the designated spots to correlate it to height, but I don't know how. Please let me know if there is another way to do this. I've only been using Matlab for 1 week and have been using youtube a lot for help. Thanks.
NON=NumberOfNeighbors
PLCm=PlantHeightcm
find PLCm when NON=1
Error using find
Second argument must be a positive scalar integer.

채택된 답변

Chunru
Chunru 2021년 9월 1일
편집: Chunru 2021년 9월 1일
neighbors = [2,1,4,1,6,7,3,1];
height = [12.5,17,10,4,16,20.4,13.2,9.4 ];
% find the entries with 1 neighbour
idx = neighbors == 1;
% use logic index to get the heights with 1 neigbour and find mean
a = mean(height(idx))
a = 10.1333
% or in one line
a = mean(height(neighbors==1))
a = 10.1333
  댓글 수: 1
Kristin Aldridge
Kristin Aldridge 2021년 9월 1일
Thank you! That's the formula I ended up using and got the appropriate answer. I appreciate it!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jeff Miller
Jeff Miller 2021년 9월 1일
NON1 = NON == 1; % this makes a boolean vector that is true for the positions where NON==1
mean(PLCm(NON1)); % this computes the mean of the PLCm values in those positions

카테고리

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