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

5 次查看(过去 30 天)
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.

回答(1 个)

KSSV
KSSV 2016-11-28
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 个评论
KSSV
KSSV 2016-11-28
Not clear to me..:(. Any example figure which you want to plot?
Morgan Clendennin
Morgan Clendennin 2016-11-28
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by