cells to double array

1 visualizzazione (ultimi 30 giorni)
Dawn
Dawn il 11 Mar 2015
Modificato: per isakson il 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 Commenti
per isakson
per isakson il 11 Mar 2015
A small example of an input and the required output would be helpful for someone who never touched C.
Dawn
Dawn il 11 Mar 2015
Im sorry, I forgot to include the attachment that contains "original".

Accedi per commentare.

Risposte (2)

per isakson
per isakson il 11 Mar 2015
Modificato: per isakson il 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 il 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.)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by