How to get the rgb code from Matlab figure

49 visualizzazioni (ultimi 30 giorni)
Hello Everyone,
I have attached a matlab figure here. This plot was generated from Matlab and I need to know the RGB color code for each color used in this picture. I know that there are exactly 5 colors have been used for this plot, I need to extract these 5 colors. Please help me to solve this problem.
Thank you.
Khalid
  2 Commenti
Adam Danz
Adam Danz il 29 Apr 2020
Modificato: Adam Danz il 29 Apr 2020
Do you have the fig file (if so, attach it) and do you know which function was used to generate the plot?
Khalid Ibne Masood
Khalid Ibne Masood il 29 Apr 2020
Hello Adam,
Thank you, here I have attached the .fig file.
I believe 'surf' was used to generate the plot.
Thank you.
Khalid

Accedi per commentare.

Risposta accettata

Adam Danz
Adam Danz il 29 Apr 2020
Modificato: Adam Danz il 29 Apr 2020
Retreiving the colors from a surface plot can be trickly due to the interaction between the color properties of a surface object. If you plan to apply this solution to a variety of surface plots with varying color properties, you'll need to carefully read about the color properties and how they interact with eachother: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.surface-properties.html#d120e1097631
See inline comments for details.
% Open the figure
fig = openfig('Question.fig');
% Find the axis handle
ax = findobj(fig, 'Type', 'axes');
% Find the surface handle
surfObj = ax.Children;
% Get the colormap
cmap = ax.Colormap;
% scale the color data values to the range of the
% colormap to match the color data with the colormap rows.
cval = round((surfObj.CData - ax.CLim(1))./range(ax.CLim) .* (size(cmap,1)-1)) +1;
% List the unique colors in order from left to right.
uniqueRGB = cmap(unique(cval(:),'stable'),:);
Results:
uniqueRGB =
0.5 0 0
0.9375 1 0.0625
0.5625 1 0.4375
0.4375 1 0.5625
0 0 0.5625
Plot a large dot above each color section to check the results
% Add dots to plot to confirm color
hold on
h = scatter3([.1 .35 .6 .80 .95], repmat(1,1,size(uniqueRGB,1)), repmat(max(ax.ZLim),1,size(uniqueRGB,1)), ...
200, uniqueRGB, 'filled', 'MarkerEdgeColor', 'k', 'LineWidth', 2);

Più risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by