필터 지우기
필터 지우기

Color in plot from Table

조회 수: 6 (최근 30일)
MattC
MattC 2023년 3월 22일
댓글: Les Beckham 2023년 3월 26일
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);
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.

답변 (1개)

Les Beckham
Les Beckham 2023년 3월 22일
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)
Table1 = 2×4 table
xaxis A B Color _____ __ __ _________ 1 10 45 "#808080" 2 15 65 "#808080"
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
MattC
MattC 2023년 3월 25일
The point is to plot the data from the table and I think I shared everything I had already. I know it is easier to just plot it directly but that is not what I am have to do
Les Beckham
Les Beckham 2023년 3월 26일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by