cells to double array

1 次查看(过去 30 天)
Dawn
Dawn 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 CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by