How fix Cell contents reference from a non-cell array object?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have cell "checked_min_max" , i want to use each cell value in creating another matrix for each loop "new_ImgAsTxt" to perform calculations on then remove it the error "Cell contents reference from a non-cell array object" appears as i the matrix is empty. How could i solve it?
for vec_len = 1:size(checked_min_max, 1)
st(vec_len, 1) = checked_min_max{vec_len, 1}(1)
nd(vec_len, 1) = checked_min_max{vec_len, 1}(2)
%
new_ImgAsTxt(u, :) = cent_TxtAsImg(find(cent_TxtAsImg(:, 6) == st(vec_len, 1)), 1:4);
new_ImgAsTxt(u + 1, :) = cent_TxtAsImg(find(cent_TxtAsImg(:, 6) == nd(vec_len, 1)), 1:4);
minx = min(new_ImgAsTxt(u:u + 1, 1));
miny = min(new_ImgAsTxt(u:u + 1, 2));
max_x = max(new_ImgAsTxt(u:u + 1, 3));
max_y = max(new_ImgAsTxt(u:u + 1, 4));
W = max_x - minx;
H = max_y - miny;
new_ImgAsTxt = [];
u = 1;
minx = 1;
miny = 1;
max_x = 1;
max_y = 1;
checked_min_max = [];
end
0 commentaires
Réponses (1)
Stephen23
le 7 Fév 2018
Modifié(e) : Stephen23
le 7 Fév 2018
The problem is this:
for vec_len = 1:size(checked_min_max, 1)
...
checked_min_max = [];
end
Although before the loop it might be a cell array, at the end of the first loop iteration you define checked_min_max to be an empty numeric array. On the second loop iteration you try to access an empty numeric array as if it were a cell array.
Solution: You do NOT need to remove any cells in the loop for your code to work, so just remove the line of code where you redefine checked_min_max. In general it is a bad idea anyway to remove array elements like this in a loop, because it forces MATLAB to move the entire array to new memory on each loop iteration.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Types 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!