Color in plot from Table
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi All, I have a table in matlab which has some columns which I trying to plot. The table also has a column for the color which I want to use as color point but when I try and use this column directly to plot the data it gives me an error. Can someone help how to plot this?
xaxis = [1,2];
A = [10,15];
B = [45,65];
Color = ["#808080","#808080"];
Table1 = table (xaxis,A,B,Color);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1333365/image.png)
Trying to plot it like:
Odds = [];
Odds(end+1) = plot(Table1.xaxis,Table1.A,'s','MarkerFaceColor','none','MarkerEdgeColor',sprintf('%s',Table1.Color));
hold on
Odds(end+1) = plot(Table1.xaxis,Table1.B,'+','MarkerFaceColor','none','MarkerEdgeColor',sprintf('%s',Table1.Color));
% This is the error I receive
% Error using plot
% Invalid color name or hexadecimal color code. Valid names include: 'red', 'green', 'blue', 'cyan',
% 'magenta', 'yellow', 'black', 'white', and 'none'. Valid hexadecimal color codes consist of '#' followed
% by three or six hexadecimal digits.
0 Kommentare
Antworten (1)
Les Beckham
am 22 Mär. 2023
Just a couple of issues. You need column vectors to insert into the table, and you can only have a scalar string or char vector for specifying the MarkerEdgeColor using a hex color code.
xaxis = [1,2]'; % <<< transpose these to get column vectors to use in creating the table
A = [10,15]';
B = [45,65]';
Color = ["#808080","#808080"]';
Table1 = table (xaxis,A,B,Color)
Odds = [];
Odds(end+1) = plot(Table1.xaxis,Table1.A,'s','MarkerFaceColor','none','MarkerEdgeColor',Table1.Color(1));
hold on
Odds(end+1) = plot(Table1.xaxis,Table1.B,'+','MarkerFaceColor','none','MarkerEdgeColor',Table1.Color(1));
xlim([0 3])
ylim([5 70])
grid on
10 Kommentare
Les Beckham
am 26 Mär. 2023
I'm pretty sure that I have shown you all of the available options for using the plot command to specify markers and colors, and how to extract data from a table. If you won't share your actual data and the code that you are using (and why, specifically, it doesn't do what you want), I can't help you any further.
Experiment with changing the code that you have (using the suggestions I gave you) until you get what you want. That is the thing that is great about Matlab, it is easy to try things and see what happens, and then change it until it does what you want.
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!