cells to double array

2 vues (au cours des 30 derniers jours)
Dawn
Dawn le 11 Mar 2015
Modifié(e) : per isakson le 11 Mar 2015
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 commentaires
per isakson
per isakson le 11 Mar 2015
A small example of an input and the required output would be helpful for someone who never touched C.
Dawn
Dawn le 11 Mar 2015
Im sorry, I forgot to include the attachment that contains "original".

Connectez-vous pour commenter.

Réponses (2)

per isakson
per isakson le 11 Mar 2015
Modifié(e) : per isakson le 11 Mar 2015
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 le 11 Mar 2015
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.)

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by