Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Creating simple, probabilistic graphics

Subject: Creating simple, probabilistic graphics

From: C F

Date: 4 Feb, 2009 08:05:03

Message: 1 of 4

Hi,
I'm relatively new to creating graphics in matlab, and wanted to know if someone had an idea how to do the following:

I have two vectors x and y. Each element of x is a probability, say .3, and the correspoding element in y is the complement of that probability, say .7. I need to create a graphic for each observation which is a square that is blue and red, where the blue area is proportional to the x probability and the y area is proportional to the Y probability. So for instance, I have a square, which is divided into 2 rectangles where the upper 30% is blue, and the lower 70% is red. Any ideas how to automate this for all observations? THanks, I know it's a bit obscure...

Subject: Creating simple, probabilistic graphics

From: us

Date: 4 Feb, 2009 08:22:02

Message: 2 of 4

"C F"
> I have two vectors x and y. Each element of x is a probability, say .3, and the correspoding element in y is the complement of that probability, say .7. I need to create a graphic for each observation which is a square that is blue and red, where the blue area is proportional to the x probability and the y area is proportional to the Y probability. So for instance, I have a square, which is divided into 2 rectangles where the upper 30% is blue, and the lower 70% is red. Any ideas how to automate this for all observations? THanks, I know it's a bit obscure...

...indeed...

one of the many solutions
- why not just use the BAR function

% the data
     x=rand(1,10);
% the plot
     bar(x,1,'facecolor',[1,0,0]);
     set(gca,...
          'xtick',[],...
          'ytick',[],...
          'color',[0,1,0]);
     axis tight;

us

Subject: Creating simple, probabilistic graphics

From: us

Date: 4 Feb, 2009 08:30:19

Message: 3 of 4

"C F"
> I have two vectors x and y. Each element of x is a probability, say .3, and the correspoding element in y is the complement of that probability, say .7. I need to create a graphic for each observation which is a square that is blue and red, where the blue area is proportional to the x probability and the y area is proportional to the Y probability. So for instance, I have a square, which is divided into 2 rectangles where the upper 30% is blue, and the lower 70% is red. Any ideas how to automate this for all observations? THanks, I know it's a bit obscure...

...indeed...

one of the many solutions
- why not just use the BAR function

% the data
     x=rand(1,10);
% the plot
     bar(x,1,'facecolor',[1,0,0]);
     axis tight;
     set(gca,...
          'xtick',[],...
          'ytick',[],...
          'ylim',[0,1],...
          'color',[0,1,0]);

us

Subject: Creating simple, probabilistic graphics

From: C F

Date: 4 Feb, 2009 18:09:02

Message: 4 of 4

"us " <us@neurol.unizh.ch> wrote in message <gmbjmr$nv3$1@fred.mathworks.com>...
> "C F"
> > I have two vectors x and y. Each element of x is a probability, say .3, and the correspoding element in y is the complement of that probability, say .7. I need to create a graphic for each observation which is a square that is blue and red, where the blue area is proportional to the x probability and the y area is proportional to the Y probability. So for instance, I have a square, which is divided into 2 rectangles where the upper 30% is blue, and the lower 70% is red. Any ideas how to automate this for all observations? THanks, I know it's a bit obscure...
>
> ...indeed...
>
> one of the many solutions
> - why not just use the BAR function
>
> % the data
> x=rand(1,10);
> % the plot
> bar(x,1,'facecolor',[1,0,0]);
> axis tight;
> set(gca,...
> 'xtick',[],...
> 'ytick',[],...
> 'ylim',[0,1],...
> 'color',[0,1,0]);
>
> us

Hi, thanks for the response. I'm not sure this gets at what I ultimately want, since this will put all 18 observations next to each other on a set of axes. What I need for each observation is a solid square, 2 inches by 2 inches, where the square is split into rectangles by and the area of each color i proportional to the probability in my x and y vectors. If it cant automate its fine, i can do it 1 by 1 and save 18 different images. Thanks again for looking...

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us