display cell array on a figure or convert to non-cell array
4 views (last 30 days)
Show older comments
Hi,
Thanks to Andrei Bobrov for answering my last question related to this. My last question was if I have a cell array
A={[1 3],[],[2 3 7 8];[2 4 5 7],[4 7 8],[];[],[],[]}
and I have a non-cell array
B=[0 0 5;0 3 0; 3 9 2]
and I want every cell where B = 0 to be equal to A for that corresponding location,
C=[[1 3],[],5;[2 4 5 7],3,[],3,9,2]
How would I combine them since one of the arrays is a cell array and one is not. Andrei's solution was as follows
Bc = num2cell(B);
t = B ~= 0;
C = A;
C(t) = Bc(t);
This sets Bc equal to B which is converted from a regular array to a cell array and then combines the two using the rules I set. My only concern now is that I have a figure with a 3x3 grid that I need to be able to display the new array on and I can't figure out how to display the individual components of a cell array on the figure. What I mean is that each component of the array would go in a different part of the grid. I know how to do this for a non-cell array which is why I was hoping there was a way to convert the cell array to a non-cell array. I know this is difficult since the components of the array are not equally sized. Any insight that anybody can give me is greatly appreciated.
0 Comments
Answers (1)
KSSV
on 28 Nov 2016
A={[1 3],[],[2 3 7 8];[2 4 5 7],[4 7 8],[];[],[],[]} ;
B=[0 0 5;0 3 0; 3 9 2] ;
% Get zeros in B
idx = find(B==0) ;
B = num2cell(B) ;
B(idx) = A(idx) ;
3 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!