Loop Failed for Extracting Matrix from Cell Arrays

1 回表示 (過去 30 日間)
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 22 日
編集済み: Angga Lisdiyanto 2016 年 1 月 22 日
The result of code below is 0 for all elements in each matrix, why?
for i=1:512
for ii=1:64
for iii=1:8
img{i} = cell_img{ii}(:,:,iii);
end
end
end
Where cell_image{ii} contains 64 cells, then for each cell is contains 8x8x8 matrix (there are 8 matrix, each one matrix contains 8x8 elements). What i want is to extract the whole matrix from the cell_image{ii}, so it would become a 64x8 = 512 matrix (each one matrix contains 8x8 elements). But the code above is resulting all matrix element become zero. What's wrong with that code?
Please help me... Thanks in advance.

採用された回答

Guillaume
Guillaume 2016 年 1 月 22 日
If you'd used the debugger to see what was happening with your loops, you would have quickly realised that you have one loop too many, the outer loop. Your i should be a counter not a loop, that is incremented by one inside the inner most loop:
i = 1;
for ii = 1:64
for iii = 1:8
img{i} = cell_image{ii}(:, :, iii); %do not use image as a variable name. It's a matlab function
i = i + 1;
end
end
However, even better is to learn to manipulate cell arrays, the above is achieved more simply with:
img = cat(3, cell_image{:});
img = squeeze(num2cell(img, [1 2])); %I would actually not bother with this step and simply keep the 3d matrix
  3 件のコメント
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 22 日
編集済み: Angga Lisdiyanto 2016 年 1 月 22 日
Thankyou very much. It's works. :)
Actually, these cells contains 8 matrix inside, result of convolutions between image with 8 kernels. So each cells contains one image filtered with 8 kernel (8 matrix/dimensions).
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 22 日
編集済み: Angga Lisdiyanto 2016 年 1 月 22 日
By the way, how to view the debugger?
Allright, i would search it at Google. Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by