How fix Cell contents reference from a non-cell array object?

2 ビュー (過去 30 日間)
Rana Sobhy
Rana Sobhy 2018 年 2 月 7 日
編集済み: Stephen23 2018 年 2 月 7 日
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

回答 (1 件)

Stephen23
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.

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by