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 6077337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:42:34+00:00 2026-05-23T10:42:34+00:00

I would like to plot a matrix of zeros and ones into a figure

  • 0

I would like to plot a matrix of zeros and ones into a figure such that for every 1 i have a marker shaped like a vertical bar is plotted ” | “. Such that when a series of 1s are on the same x axis, the look like a long straight line.

This example illustrates my intentions:

Given the following matrix:

0 0 1 1 0 1 0
0 1 0 1 1 1 0
0 1 0 1 1 1 0
1 0 0 1 1 1 0

I get:

Bar Figure

  • 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-23T10:42:35+00:00Added an answer on May 23, 2026 at 10:42 am

    EDIT:

    The solution below, although a bit longer than the currently accepted one, has the advantage that it creates a single LINE object (UI performance is better if you create fewer graphics objects). It works by using NaN to separate the segments:

    %#A = [1 1 1 ; 0 0 0 ; 1 1 1];
    A = [
        0 0 1 1 0 1 0
        0 1 0 1 1 1 0
        0 1 0 1 1 1 0
        1 0 0 1 1 1 0
    ];
    
    %# build line x/y points
    [m n] = size(A);
    [x y] = meshgrid(1:n, 1:m);    %# grid coordinates
    x(~A) = NaN;                   %# place NaNs where A is zero
    y(~A) = NaN;
    x = [x;NaN(1,n)];              %# separate columns by NaNs
    y = [y;NaN(1,n)];
    x = [x(:) x(:)]';              %'# add endpoints
    y = [y(:) y(:)+1]';            %'#
    x = x(:);                      %# linearize
    y = y(:);
    
    %# plot
    line('XData',x, 'YData',y-0.5, 'Color','k', 'LineStyle','-', 'LineWidth',4)
    set(gca, 'XGrid','on', 'Box','on', 'FontSize',8, 'LineWidth',2, ...
        'XLim',[0 n]+0.5, 'YLim',[0 m]+0.5, 'XTick',1:n, 'YTick',1:m, ...
        'YDir','reverse')
    %#set(gca, 'XTick',[], 'YTick',[])
    

    enter image description here
    enter image description here

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

Sidebar

Related Questions

I have param as a matrix like below; I would like to plot param.num_av_BS
I have a dataframe that I would like to plot in a similar way
I have a list of ~300 IP addresses that I would like to plot
I would like to center a title with respect to a plot matrix (and
I have a large real 1-d data set called r. I would like plot:
I would like to plot a vertical line (I'd prefer any orientation, but I'd
I would like to plot an image at a random position every time the
I would like to make a plot with ggplot that looks very close to
I would like to plot two sets of values on a bar chart, that
I have a distance sequence, which I would like to plot of a line

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.