I'm certain that there is a way for me to vectorize this loop but I can't see it
TestRan is a 170x1 double
CorrectVector is a 90x1 double, a subset of TestRan
I need to populate a 170x1 double CorrectLogical with 0/1 based on CorrectVector
what I have:
CorrectLogical = zeros(length(TestRan,1))
for i=1:length(CorrectVector)
CorrectLogical(TestRan==CorrectVector(i)) = 1
end

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 25일
편집: Azzi Abdelmalek 2013년 11월 25일

0 개 추천

CorrectLogical = zeros(size(TestRan))
CorrectLogical(ismember(TestRan,CorrectVector))=1

추가 답변 (2개)

Tyler Davis
Tyler Davis 2013년 11월 25일

0 개 추천

that's it! thx for the quick help
Image Analyst
Image Analyst 2013년 11월 25일

0 개 추천

CorrectLogical = ismember(TestRan, CorrectVector)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 11월 25일

답변:

2013년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by