Changing Cell Array Dimension

7 ビュー (過去 30 日間)
bayoishola20
bayoishola20 2014 年 9 月 19 日
コメント済み: bayoishola20 2014 年 9 月 20 日
Please I have a cell array as below but need it to be in 2 dimension, that is m-by-n instead of m-by-n-by-p.
segmented_images =
Columns 1 through 3
[2592x4608x3 unit8] [2592x4608x3 unit8] [2592x4608x3 unit8]
Columns 4 through 6
[2592x4608x3 unit8] [2592x4608x3 unit8] [2592x4608x3 unit8]
Thank you.

採用された回答

the cyclist
the cyclist 2014 年 9 月 19 日
編集済み: the cyclist 2014 年 9 月 19 日
Do you want each 3D array to remain inside its cell, as it is now? If so, I think your best bet is to use the cellfun() function, which will perform an operation on each cell of an array.
You can use the reshape() function (as the first argument to cellfun).
You want to look at the documentation for these two functions, and try them out separately to see what they do, before trying them both on your problem.
That being said, here is some code that works, to give you some idea of the syntax.
new_image = cellfun(@(x)reshape(x,2592*3,4608),segmented_images,'UniformOutput',false)
BUYER BEWARE: I don't know if this actually reshapes your images the way you intend to. You'll need to do some testing to confirm the output.
  3 件のコメント
Pierre Benoit
Pierre Benoit 2014 年 9 月 19 日
See double
I think it will be best to ask another question for the use of the confusion matrix since it's totally unrelated to this question.
bayoishola20
bayoishola20 2014 年 9 月 19 日
okay!thanks on that @ Pierre Benoit

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 9 月 19 日
What you said makes no sense. It's a 1D cell array. You can reshape it into a 2D array with reshape
segmented_images = reshape(segmented_images, [m,n]);
Saying "m-by-n instead of m-by-n-by-p." is nonsense because, like I said, the cell array is 1 by 6 not "m-by-n-by-p". The contents of a cell array are independent of the dimensions of the cell array itself. Think of a cell array as an array of buckets, with each cell being one bucket. Now you can thrown whatever you want into any of the buckets: strings, 2D or 3D arrays, structures, tables, or whatever you want, but that doesn't affect the arrangement of the buckets (how many buckets there are or how many rows or columns of buckets there are). See the FAQ for a better explanation. http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
  4 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 20 日
I don't have the Statistics Toolbox so I can't run kmeans.
bayoishola20
bayoishola20 2014 年 9 月 20 日
okay!thanks

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by