Formatting the color/font of a Cellplot using code
16 views (last 30 days)
Show older comments
Hello,
I have written a code that randomly places a specific number of symbols in a 4x4 matrix and fills the rest of the cells with *'s. I want a code that can save this matrix (or cell array) as a figure that is a white background with only black numbers or stars. I was able to use the cellplot function to make a figure of the cell array. However, I cannot find any information on code that can change the physical appearance of the cellplot. If you plot it you can see that the numbers appear in colourful squares. It is possible to do this manually using the figure properties GUI, however I need to make thousands of these matrices and therefore would like to automatize making, saving and naming the figure. I have copied and pasted my code below. Any help on this would be greatly appreciated!
n = 4
p = 2
A = repmat('*', 4, 4)
rp = randperm(4*4)
A(rp(1:p))= num2str(n)
A1 = num2cell(A)
cellplot(A1)
0 Comments
Answers (2)
John BG
on 26 Apr 2016
Edited: John BG
on 26 Apr 2016
you can generate multiple figures placing the command figure with the numeral differentiating each figure window. For instance:
n = 4
p = 2
A = repmat('*', 4, 4)
rp = randperm(4*4)
A(rp(1:p))= num2str(n)
A1 = num2cell(A)
figure(1);cellplot(A1)
title('figure 01')
save(file_A1.mat,'A1')
rp = randperm(4*4)
A(rp(1:p))= num2str(n)
A1 = num2cell(A)
figure(2);cellplot(A1)
title('figure 02')
save(file_A2.mat,'A1')
different figures and different .mat files saving each cell.
You can also save the entire workspace with simply
save(file1.mat)
Load .mat files with
load('file_name.mat')
Or direct 'casting' line by line:
fid2=fopen('example_text2.txt','w')
for k=1:1:length(A)
B0=A1(k,1)
fwrite(fid2,B0,'char')
end
fclose all
Repeat for each cell. To automate many cells generation and storage, first put all the file names, and figure titles in separate lists and the automate with a for loop, feeding figure(k)l .. and for each file name.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John
John BG
on 27 Apr 2016
Edited: John BG
on 27 Apr 2016
with
colormap autumn
the default colour map for surf is parula, haven't checked for cellplot, or
colormap jet
or defining your custom colormap
saturated colours are
Color RGB Triplet
yellow [1,1,0]
magenta [1,0,1]
cyan [0,1,1]
red [1,0,0]
green [0,1,0]
blue [0,0,1]
white [1,1,1]
black [0,0,0]
reduce the values to zero for dark, any real positive value between [0 1] are accepted.
an example of custom colormap would be for instance:
map1 = [0.2, 0.1, 0.5
0.1, 0.5, 0.8
0.2, 0.7, 0.6
0.8, 0.7, 0.3
0.9, 1, 0];
applied to
colormap(map1)
Would it be possible for you either accept this answer or simply click on the vote thumbs-up link next to my answer
thank in advance
John
0 Comments
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!