How fix Cell contents reference from a non-cell array object?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Stephen23
2018년 2월 7일
편집: Stephen23
2018년 2월 7일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!