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

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.

Risposte (1)

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 Commenti

Hi KSSV,
I'm not sure if you understand my question exactly so let me try and explain it a little better. Doing it the way that I explained above, I have a cell array that I want to be able to display on a figure that has each component of the cell array in a different grid box on the figure. I understand how to do this for a regular, non-cell array which is why I was hoping to convert A to a non-cell array and then insert into B not to convert B into a cell array and then combine. But since it doesn't look like I can convert A into a non-cell since each component of the array is not the same size, what would my syntax be for displaying each individual component of the combined array onto the figure with each component in a different grid box on the figure? Let's say I have just an arbitrary grid figure for now.
Not clear to me..:(. Any example figure which you want to plot?
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.

Accedi per commentare.

Categorie

Scopri di più su Labels and Styling in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by