-1

Would someone kindly please tell me why imagesc is not doing what I want it to:

I am trying to get a grid of chars out like:

http://wetans.net/word-search-worksheets-for-kids

Here is the code:

A = [5,16,18,4,9;
    9,10,14,3,18;
    2,7,9,11,21;
    3,7,2,19,22;
    4,9,10,13,8]

AAsChars = char(A + 96);

imagesc(AAsChars);
user3071257
  • 37
  • 1
  • 7

2 Answers2

1

The short answer is - you are using the wrong function for your job. imagesc will take a map of values and convert it to intensities - one pixel per value. You want it to magically take a character value and turn it into the representation (many pixels) of the character that this represents (without regard to font, etc).

You probably want to create an empty background, then put text characters at the locations you want. Something like (not tested):

figure
imagesc(ones(5,5))
axis off
for t = 1:5
  for k = 1:5
    text(t, k, sprintf('%c', A(t,k) + 96))
  end
end

This should put the string (character) at the location (i,j). Experiment a bit - not sure I have the syntax of text() and the formatting of the string (with "%c") right and can't check right now.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
Floris
  • 45,857
  • 6
  • 70
  • 122
  • That's great thanks. Is there a way of removing the green though and making black letters in a grey background? – user3071257 Dec 11 '13 at 16:05
  • @DennisJaheruddin thanks - I was writing C all morning and didn't have a Matlab environment available. As for the green etc - you can make your color map anything you want it to be (`colormap gray` should get the background color that you want), and you can set properties of the text by adding `, 'Color', [0 0 0]` (for black) to the end of the `text` command. See http://www.mathworks.com/help/matlab/ref/colorspec.html – Floris Dec 11 '13 at 16:09
  • One more thing sorry. How do I plot a line over the top of the image? Between specified co-ordinates say between (1,2) and (4,5)? – user3071257 Dec 11 '13 at 17:46
0

I think you are overcomplicating, this should simply do the trick:

char(A + 96)
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122