Hi everyone,
I am trying to add weights to a set of observations based on their year. So, I have 150 observations across 30 unique years. I have one weight per year. I would like to broadcast the weights to the 150 observations linking based on year. I understand that this can be done using database join functionality but I am wondering if there is a way to do this just using matrices.
To restate: My weights matrix is 30x2 (unique years x [years weights]). My data matrix is 150x2 (num observations x [year blank-waiting-for-weight].
Computational efficiency is critical here so that's why I'm trying to avoid conversions if possible.
Thanks for your thoughts, Mike

 채택된 답변

dpb
dpb 2015년 12월 7일

1 개 추천

[~,lib]=ismember(dat(:,1),w(:,1)); % location of year in data
dat=[dat w(lib,2)]; % concatenate the weights in those rows

댓글 수: 1

Mike Alonzo
Mike Alonzo 2015년 12월 7일
Perfect. Thanks. Forgot about the second output of ismember.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 12월 7일

댓글:

2015년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by