i have cell array m [1x4] [1x5] and a cell array named y whose dimensions are [1x4] [1x5]. i want to put the y cell array into m such that resulting m is [1x8] [1x5] e.g
m{1}=2 3 6 44
m{2}= 12 34 25 66
and
y{1}=10 5 1 8
y{2}=3 0 9 6 7
resulting m should be
m{1}=2 3 6 44 10 5 1 8
m{2}=12 34 25 66 3 0 9 6 7

 채택된 답변

James Tursa
James Tursa 2017년 9월 12일
편집: James Tursa 2017년 9월 12일

0 개 추천

m = cellfun(@(A,B)[A B],m,y,'uni',false);

댓글 수: 5

Shivik Garg
Shivik Garg 2017년 9월 12일
thanks a lot
Shivik Garg
Shivik Garg 2017년 9월 12일
편집: Shivik Garg 2017년 9월 12일
if m initially is empty how do you add y to it using the function that you have mentioned?
You will need to add code to initialize m. E.g., something like this
m = cell(size(y));
Or maybe you will need to have this execute conditionally, e.g.,
if( isempty(m) )
m = cell(size(y));
end
It is hard to say what the correct way of initializing m will be without seeing the code prior to the merger and where m comes from initially.
Shivik Garg
Shivik Garg 2017년 9월 12일
initially m={}. i generate y of different sizes and keep adding it to m
James Tursa
James Tursa 2017년 9월 12일
편집: James Tursa 2017년 9월 12일
So, if m={} initially, then you can use the 2nd method above with the if-test. Just put that immediately prior to the cellfun call.
But, what do you mean by "generate y of different sizes"? Will y have a different number of cell elements on each iteration? E.g., is it possible that on one iteration y will have 2 vectors, but on another iteration if might have 5 vectors?

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

추가 답변 (0개)

카테고리

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

태그

질문:

2017년 9월 12일

편집:

2017년 9월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by