How do I fix the Function 'subsindex' is not defined for values of class 'cell' in my code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The code below returns the error 'Function 'subsindex' is not defined for values of class 'cell'.'
Error in main_lameness_algo (line 93)
if (mean(Dprev(refimage{g,1})))<((refimage{g,2})+50) && ((refimage{g,2})-50)<(mean(Dprev(refimage{g,1})))
Please how can I fix it
refimage = cell(5,3);
n = 1;
while 1
n = n+1;
filename = ['f' num2str(n) '.txt'];
[A2]=importdata(filename);
B2 = reshape(A2,[512,424]);
C2 = transpose(B2);
rowstart2 = 1;
rowstop2 = 370;
colstart2 = 50;
colstop2 = 512;
D2 = C2(rowstart2:rowstop2,colstart2:colstop2);
D2(D2<1) = 2600;
D2(D2<2000) = 2600;
filenameprev = ['f' num2str(n-1) '.txt'];
[Aprev,delimiterOut]=importdata(filenameprev);
Bprev = reshape(Aprev,[512,424]);
Cprev = transpose(Bprev);
rowstartprev = 1;
rowstopprev = 370;
colstartprev = 50;
colstopprev = 512;
Dprev = Cprev(rowstartprev:rowstopprev,colstartprev:colstopprev);
Dprev(Dprev<1) = 2600;
Dprev(Dprev<2000) = 2600;
pigtime = 0;
thresholdValue2 = 0.7;
originalImage2 = mat2gray(D2,[1600 2600]);
binaryImage2 = originalImage2 < thresholdValue2; % Bright objects will be chosen if you use >.
binaryImage2 = imfill(binaryImage2, 'holes');
binaryImage2 = bwareaopen(binaryImage2,5000); %remove blobs less than certain pixels
labeledImage2 = bwlabel(binaryImage2, 8);
blobMeasurements2 = regionprops(labeledImage2, D2, 'all');
numberOfBlobs2 = size(blobMeasurements2, 1);
if numberOfBlobs2<1
continue
end
for g = 1 : numberOfBlobs2 % Loop through all blobs (sitting pigs).
thisBlobsPixels = blobMeasurements2(g).PixelIdxList; % Get list of pixels in current blob.
refimage{g,1} = {thisBlobsPixels};
thisBlobsPixvals = blobMeasurements2(g).PixelValues; % Get list of pixels values in current blob.
refimage{g,2} = {mean(thisBlobsPixvals)};
%refimage{g,3} = {pigtime};
if (mean(Dprev(refimage{g,1})))<((refimage{g,2})+50) && ((refimage{g,2})-50)<(mean(Dprev(refimage{g,1})))
refimage{g,3} = (refimage{g,3}) + 5;
end
end
if n ==20
break
end
end
Réponse acceptée
Matt J
le 10 Oct 2018
Modifié(e) : Matt J
le 10 Oct 2018
I think you mean to have,
refimage{g,1} = thisBlobsPixels;
refimage{g,2} = mean(thisBlobsPixvals);
%refimage{g,3} = pigtime;
In any case, the error message means you have tried to use a cell element to index into a numeric array, as in the following,
x=[5,6,7];
x({1}), %doesn't work
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!