display cell array on a figure or convert to non-cell array

4 views (last 30 days)
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.

Answers (1)

KSSV
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
KSSV
KSSV on 28 Nov 2016
Not clear to me..:(. Any example figure which you want to plot?
Morgan Clendennin
Morgan Clendennin on 28 Nov 2016
the code for the figure and the grid are
Window=get(0,'ScreenSize');
display=figure('Name','Sudoku','NumberTitle','off','Resize','on','menubar','none','Units','pixels','position',[1.85*(Window(4)-700),1.85*(Window(4)-700),600,600]);
for r=1:3;
for c=1:3;
up=(ceil(c/3)-2)*0.025;
across=(ceil(r/3)-2)*0.025;
Matrix(r,c)=uicontrol('Parent',display,'Style','edit','String','','Enable','on','Units','normalized','position',[0.0825+0.065*r+across,0.855-0.075*c-up,0.075,0.075]);
end
end
And I want to put one component of the cell array, let's say the first row and first column for example, in the corresponding first row and first column of the grid.

Sign in to comment.

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!