Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
For loop Issue, Loops, Row Col Indexing Issue
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ingrid
am 7 Apr. 2015
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 Kommentare
Ingrid
am 8 Apr. 2015
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;
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!