How to use one data set to find the mean of another?
1 view (last 30 days)
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.
find PLCm when NON=1
Error using find
Second argument must be a positive scalar integer.
Chunru on 1 Sep 2021
Edited: Chunru on 1 Sep 2021
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))
% or in one line
a = mean(height(neighbors==1))