Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
For loop Issue, Loops, Row Col Indexing Issue
조회 수: 3 (최근 30일)
이전 댓글 표시
Experts, I stuck in the logic of for loop,
load 'D:\MS\Research\Classification Model\Research Implementation\test.mat'; % loading test data i.e cp
[rI,cI] = size(cp);% size of test data
resultantImage = zeros(rI,cI); % image to store classified pixels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:length(resultantImage)
classes = svmclassify(SVMModel,cp(rI(i),cI(i)),'Showplot', true);
if (classes == 'Y')
resultantImage(rI(i),cI(i)) = 1;
classes = 1;
else if (classes == 'N')
resultantImage(rI(i),cI(i)) = 0;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In the above for loop i want to extract the value from 'cp' variable and pass it to classifier for classification once i have pixel classified as 'Y' or 'N', i use the row col index of the pixel and store either 1 or 0 at the same row col index of resultant image. I have written the above logic but resultant image is not getting populated with 1 or 0 values it remains zeros array!!!!!!!!! Please help
댓글 수: 0
답변 (1개)
Ingrid
2015년 4월 7일
This does not seem to be a problem with the for-loop. Are you sure that the SVMM model is correct and that it gives as output 'Y' and 'N' as possible groups? You can check for this by not using an if but a switch so in your case:
for i=1:length(resultantImage)
classes = svmclassify(SVMModel,cp(rI(i),cI(i)),'Showplot', true);
switch classes
case 'Y'
resultantImage(rI(i),cI(i)) = 1;
case 'N'
resultantImage(rI(i),cI(i)) = 0;
otherwise
error('Not classified in the correct class')
end
end
I always use the switch option when working with string variables as it makes the code more clear to read even if there are no problems in the implementation
댓글 수: 4
Ingrid
2015년 4월 8일
you do not need to use the for-loop, vectorizing your solution would be much faster. This would look something like this
resultantImage = zeros(size(cp));
allClasses = svmclassify(SVMModel, cp, 'Showplot',true);
idx = (strcmpi(allClasses,'Y'));
resultantImage(idx) = 1;
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!