hello i have a cell array 7x7
Columns 1 through 6
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
Column 7
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
I want to concatenate all t he cells in this cell array to a 7x7x256=12544x1 vector how do i do that ?

 채택된 답변

Image Analyst
Image Analyst 2016년 7월 17일

0 개 추천

Try this:
ca = ca{:}

댓글 수: 4

Newman
Newman 2016년 7월 17일
it is returning 256x1 not 12544x1
Image Analyst
Image Analyst 2016년 7월 17일
편집: Image Analyst 2016년 7월 17일
Then try using mat2cell(). Or just a simple for loop if you want
ca2 = [];
for k = 1 : numel(ca)
ca2 = [ca2; ca{k}];
end
Newman
Newman 2016년 7월 17일
thanks
Image Analyst
Image Analyst 2016년 7월 17일
You're welcome, though you should really not even use cell arrays in the first place. They are for using mixed data types (though this has been supplanted by the new "table" data type in most cases), or for arrays of strings of different lengths. They were not meant for arrays of simple numerical arrays, which could be handles by a simple 2D numerical array in your case.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 17일
편집: Azzi Abdelmalek 2016년 7월 17일

1 개 추천

a=arrayfun(@(x) rand(256,1),ones(7),'un',0)
out=reshape(cell2mat(a),[],1)

댓글 수: 3

Image Analyst
Image Analyst 2016년 7월 17일
Thanks Azzi, I knew there had to be a way.
I think the original poster should not even have used a cell array in the first place. Since all cell contents were double arrays, he should have just used a simple numerical matrix and not mess around with cell arrays.
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 17일
Image Analyste I don't understand the thanks for what? but I agree with you that some choices are really incomprehensible!
Image Analyst
Image Analyst 2016년 7월 17일
Well, you used reshape() and I did the "for" loop. While a for loop might be easier for beginners to understand, reshape() is possibly the more "MATLAB-ish" way to do it. And it can be complicated/confusing to figure out when to use brackets, braces, and parentheses with cell arrays, even for us experienced people that's why I recommend beginners to avoid them if they can.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2016년 7월 17일

댓글:

2016년 7월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by