Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6358041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:17:29+00:00 2026-05-24T23:17:29+00:00

Possible Duplicate: How do I visualize a matrix with colors and values displayed? I

  • 0

Possible Duplicate:
How do I visualize a matrix with colors and values displayed?

I basically have a NxN (edit:N can be up to 80) matrix of double in MATLAB and I when to plot it as an array (I want to see the numbers) and some of the cells should be colored (the function to decide how I color my numbers is independent from the numbers).

I have thought of different ways to do that :

  • create an grid as an image and overlay it with the text but the plot of MATLAB is going to be horrible as it will remove some pixels to resize the image (my matrix can be around 80x80).

  • Export to excel ? Don’t know how I would color the cells though.

Any help ?

As an image is sometimes more helpful :

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:17:30+00:00Added an answer on May 24, 2026 at 11:17 pm

    Consider the following code:

    %# matrix
    M = rand(11,11);
    [r c] = size(M);
    
    %# text location and labels
    [xloc yloc] = meshgrid(1:c,1:r);
    xloc = xloc(:); yloc = yloc(:);
    str = strtrim(cellstr( num2str(M(:),'%.3g') ));
    xticklabels = cellstr( num2str((1:c)','M%d') );
    yticklabels = cellstr( num2str((1:r)','M%d') );
    
    %# plot colored cells
    mask = M>0.9;               %# or any other mask
    h = imagesc(1:c, 1:r, ones(size(M)));
    set(h, 'AlphaData',mask)
    colormap(summer)            %# colormap([0 1 0])
    set(gca, 'Box','on', 'XAxisLocation','top', 'YDir','reverse', ...
        'XLim',[0 c]+0.5, 'YLim',[0 r]+0.5, 'TickLength',[0 0], ...
        'XTick',1:c, 'YTick',1:r, ...
        'XTickLabel',xticklabels, 'YTickLabel',yticklabels, ...
        'LineWidth',2, 'Color','none', ...
        'FontWeight','bold', 'FontSize',8, 'DataAspectRatio',[1 1 1]);
    
    %# plot grid
    xv1 = repmat((2:c)-0.5, [2 1]); xv1(end+1,:) = NaN;
    xv2 = repmat([0.5;c+0.5;NaN], [1 r-1]);
    yv1 = repmat([0.5;r+0.5;NaN], [1 c-1]);
    yv2 = repmat((2:r)-0.5, [2 1]); yv2(end+1,:) = NaN;
    line([xv1(:);xv2(:)], [yv1(:);yv2(:)], 'Color','k', 'HandleVisibility','off')
    
    %# plot text
    text(xloc, yloc, str, 'FontSize',8, 'HorizontalAlignment','center');
    

    screenshot

    As you increase the size of the matrix, the text will eventually overlap…


    EDIT

    Here is a way that works with larger matrices: we use an invisible figure, resize it to something big enough, and use a small font size (I used 2):

    M = rand(80,80);
    
    figure('visible','off')
    set(gcf, 'Units','Pixels', 'Position', [0, 0, 10000, 10000], ...
         'PaperPositionMode','Auto');
    set(gca, 'units','normalized', 'position',[0.05 0.02 0.9 0.95])
    
    %# ... 
    

    Then at the end, export to file with a high resolution:

    %# ...
    
    print -dpng -r600 file.png
    

    You can see the output file here (10025×5962 image, 645KB)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Multiple forms on ASP.NET page i have a doubt. can we place
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: How can I take screenshots with Perl? How can I take a
Possible Duplicate: Parsing text in C Say I have written to a text file
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Split A4 PDF page into two A5 and back again I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.