cells to double array
조회 수: 2 (최근 30일)
이전 댓글 표시
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
2015년 3월 11일
A small example of an input and the required output would be helpful for someone who never touched C.
답변 (2개)
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
댓글 수: 0
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.)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!