need help vectorizing a loop
Show older comments
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
Accepted Answer
More Answers (2)
Tyler Davis
on 25 Nov 2013
0 votes
Image Analyst
on 25 Nov 2013
CorrectLogical = ismember(TestRan, CorrectVector)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!