필터 지우기
필터 지우기

Insert cell array objects into a pre-made array

조회 수: 1 (최근 30일)
Morgan Clendennin
Morgan Clendennin 2016년 11월 25일
댓글: Morgan Clendennin 2016년 11월 25일
Hi,
I am wondering if there is a way to enter the contents of a cell array into another array. I need this to be something I can do for cell arrays with contents that are of varying sizes. Let me give an example of what I mean. Let's say I have the following pre-made cell array
A={[1 3],[],[2 3 7 8];[2 4 5 7],[4 7 8],[];[],[],[]}
and now let's say I have the follow non-cell array
B=[0 0 5;0 3 0; 3 9 2]
Let's say I want to take A and everywhere in B where this is a zero, replace it with the corresponding location in A. So it would look like this
C=[[1 3],[],5;[2 4 5 7],3,[],3,9,2]
I am confused as to how or if I can do this. I know I can't just convert A to a non-cell array since each of the components of it are not the same size.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 11월 25일
Bc = num2cell(B);
t = B ~= 0;
C = A;
C(t) = Bc(t);
  댓글 수: 1
Morgan Clendennin
Morgan Clendennin 2016년 11월 25일
Hi Andrei,
Thank you for submitting a response to my question. I see that you converted the non-cell array to a cell array and the combined the two arrays together. I am concerned that this will not meet my needs though as I have a figure with a grid and I need to be able to display each component of the array on the grid in a different box. I know how to do this with a non-cell array. Is it possible to combine the two arrays without having to convert the A array to a cell array before combining or do you know of the necessary syntax to be able to display the now cell-array onto a grid figure? I'm sorry if this explanation doesn't exactly make sense and I would be more than willing to try and explain it differently.

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

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by