Cannot get imagesc to work in Matlab

88 views Asked by At

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);
2

There are 2 answers

3
Floris On

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.

0
Dennis Jaheruddin On

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

char(A + 96)