assign background color to average of points

1 view (last 30 days)
Hey guys! I am new to matlab and I am trying to figure this problem out... I have a program that calculates some operations and then gives me a series of numbers of 1, 2 or 4 (the variable’s name with the numbers 1, 2 or 4 is S) which then I plot (Image2 in attached files).
I would like each point to be the average of the three points (the one before and the one after and the point himself) and assign a color to the background for each number. For ex, when the average is 1, I would like a red color in the background, dark blue for 2 and yellow for 4 (if other colors are better, I am open to it). When the average is not 1, 2 or 4 but:
- 1+1+2 (or 1+2+1, or 2+1+1)=4/3=1.333
- 1+2+2=5/3=1.667
- 1+1+4=6/3=2
- 1+4+4=9/3=3
- 2+2+4=8/3=2.667
- 2+4+4=10/3=3.333
I would like an intermediary color.
For the numbers between 1 and 2 I would like to assign colors between red and dark blue: - Pink for 1,333 and purple for 1,667
For the numbers between 1 and 4 I would like to assign colors between red and yellow: - Pale orange for 2 and dark orange for 3
For the numbers between 2 and 4 I would like to assign colors between blue and yellow: - Green for 2.667 and pale blue for 3.333
The aim is to have a kind of continuity (visually) between the numbers from 1 to 4, and would look something like the Image3 (only the beginning).
Thanks in advance for any help!!

Answers (1)

Image Analyst
Image Analyst on 7 Feb 2017
Edited: Image Analyst on 7 Feb 2017
Try conv() or movmean()
aveSignal = conv(signal, ones(1,3)/3, 'same');
Then use patch() or fill() to fill the rectangles with color.
  8 Comments
Anastasia
Anastasia on 7 Mar 2017
Hello, only RGB image would be perfect, without the graph! Thank you for your response!
Image Analyst
Image Analyst on 7 Mar 2017
Edited: Image Analyst on 7 Mar 2017
Unfortunately you forgot to attach your data. I'll check back later for it. And how many distinct colors do you want? Is your data integers only, or fractional numbers? Do you want one color for each integer? Or thousands of colors for thousands or millions of possible floating point numbers?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!