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!