cells to double array

1 回表示 (過去 30 日間)
Dawn
Dawn 2015 年 3 月 11 日
編集済み: per isakson 2015 年 3 月 11 日
I have a 21x1 cell and in each entry of the cell and I wish to deliminate the numbers. When every row of the cell entries have been delimited, I need to convert it to a array of doubles. Basically, this is an image data that is stored in cells.
I did the following to deliminate the entries but I'm not sure how to convert C into an array of doubles from there.
Would appreciate any help. Thanks.
C = [];
for n = 1:size(a,1)
C = [C;strsplit(original{n})];
end
  2 件のコメント
per isakson
per isakson 2015 年 3 月 11 日
A small example of an input and the required output would be helpful for someone who never touched C.
Dawn
Dawn 2015 年 3 月 11 日
Im sorry, I forgot to include the attachment that contains "original".

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

回答 (2 件)

per isakson
per isakson 2015 年 3 月 11 日
編集済み: per isakson 2015 年 3 月 11 日
This is start ( a was missing so I guessed)
C = [];
for n = 1:21
C = [ C; reshape( sscanf( original{n}, '%f'), 1,[] ) ];
end
This code is similar to yours. It can be improved
  • preallocate C
  • assign rows rather than concatenate. Avoid changing the size of C

Star Strider
Star Strider 2015 年 3 月 11 日
Do you have a (21x1) cell array of images?
What are the sizes of the images, are they all the same size, and what exactly do you want to do with them?
If they’re all the same size and you want to convert the entire array of them to double, you can do something like this:
original = {uint8(randi([0 255], 10, 12)); uint8(randi([0 255], 10, 12)); uint8(randi([0 255], 10, 12))};
C = [];
for k1 = 1:size(original,1)
C = cat(3, C, original{k1});
end
Cd = double(C);
It concatenates them along the third dimension of ‘C’ and converts them to double in ‘Cd’. (I created ‘Cd’ to be sure the code worked and I could check it. You can reassign the double array to ‘C’ if you wish.)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by