colorbar in GUI matlab

5 views (last 30 days)
Hgcvghh Vbbbb
Hgcvghh Vbbbb on 22 Jan 2016
Commented: Walter Roberson on 23 Jan 2016
hello i want this colorbar by coding any help??

Answers (1)

Walter Roberson
Walter Roberson on 22 Jan 2016
A close approximation would be
image(reshape(flipud(jet(256)),[],1,3));
set(gca, 'dataaspectratio', [1 15 1], 'xticklabel',{},'yticklabel',{})
Your version has more purple at the bottom. You could start with the jet() colormap and add some purple to it.
Shorter for your purposes:
colormap(jet(256));
cb = colorbar();
set(cb, 'xticklabel',{}, 'yticklabel', {}); %not guaranteed in R2014b or later
  2 Comments
Hgcvghh Vbbbb
Hgcvghh Vbbbb on 22 Jan 2016
the margin of green isn't why i need.
Walter Roberson
Walter Roberson on 23 Jan 2016
I extracted data from your image. The data is
c18 = uint8([241 6 0;241 11 0;241 17 0;241 22 0;241 27 0;241 33 0;241 38 0;241 43 0;241 49 0;241 55 0;241 60 0;241 65 0;241 71 0;241 77 0;241 81 0;241 87 0;241 93 0;241 98 0;241 103 0;241 109 0;241 114 0;241 120 0;241 125 0;241 130 0;241 136 0;241 141 0;241 146 0;241 152 0;241 158 0;241 162 0;241 168 0;241 174 0;241 179 0;241 184 0;241 190 0;241 196 0;241 201 0;241 206 0;241 212 0;241 217 0;241 223 0;241 228 0;240 232 0;235 233 0;230 233 0;226 234 0;220 235 0;215 235 0;211 236 0;206 237 0;201 237 0;196 238 0;192 238 0;187 239 0;182 240 0;178 240 0;172 241 0;167 241 0;162 241 0;156 241 0;150 241 0;145 241 0;140 241 0;134 241 0;129 241 0;124 241 0;118 241 0;112 241 0;108 241 0;102 241 0;96 241 0;91 241 0;86 241 0;80 241 0;75 241 0;69 241 0;64 241 0;59 241 0;53 241 0;47 241 0;43 241 0;37 241 0;31 241 0;26 241 0;21 241 0;17 241 2;15 241 6;14 241 9;13 241 14;12 241 18;10 241 23;9 241 26;9 241 31;7 241 35;6 241 40;5 241 43;4 241 48;2 241 52;1 241 57;0 241 60;0 241 66;0 241 72;0 241 77;0 241 82;0 241 88;0 241 94;0 241 98;0 241 104;0 241 110;0 241 115;0 241 120;0 241 126;0 241 131;0 241 137;0 241 142;0 241 147;0 241 153;0 241 159;0 241 163;0 241 169;0 241 175;0 241 180;0 241 185;0 241 191;0 241 196;0 241 201;0 241 207;0 241 213;0 239 216;0 235 218;0 232 220;0 229 221;0 225 223;0 221 225;0 217 227;0 214 229;0 211 230;0 207 232;0 203 234;0 200 236;0 196 238;0 193 239;0 189 241;0 183 241;0 178 241;0 172 241;0 167 241;0 162 241;0 156 241;0 150 241;0 145 241;0 140 241;0 134 241;0 128 241;0 123 241;0 117 241;0 112 241;0 107 241;0 101 241;0 95 241;0 91 241;0 85 241;0 79 241;0 74 241;0 69 241;0 63 241;0 58 241;0 52 241;0 47 241;0 42 241;0 36 241;2 32 241;5 30 241;8 27 241;10 26 241;14 23 241;17 21 241;20 18 241;23 16 241;26 13 241;28 11 241;31 9 241;35 7 241;38 4 241;41 2 241;44 0 241;50 0 241;55 0 241;60 0 241;66 0 241;72 0 241;77 0 241;82 0 241;88 0 241;94 0 241;98 0 241;104 0 241;110 0 241;115 0 241]);
c18p = reshape(c18, [], 1, 3);
subplot(1,2,1);
image(c18p);
title('color as sample image');
subplot(1,2,2);
h = plot(c18);
set(h(1),'color','r'); set(h(2),'color','g'); set(h(3),'color','b')
title('plot by channel')
Now you could simply
colormap(c18)
to get those exact values, since the assignment to c18 is "by program".
If you want to compute the values then you need to have a closer look at the plot by channel, and notice that on the green channel, from about 43 to 56, and about 171 to 186, the slope channels relative to what is around it. Likewise for the red from about 86 to 100, and the blue from about 129 to 143. (The red after 171 might possibly be a bit wobbly but I suspect that you would not notice the difference if you straightened that out.) You need to decide whether those slope changes are important to be preserved or if instead you want to straighten each of those out. If you straighten them out then you end up with straight lines, and with breakpoints that you could convert to "fraction of the range" and so you would be able to compute the general case fairly simply.

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!