フィルターのクリア

how can i get same color graph in each iteration of for loop?

41 ビュー (過去 30 日間)
shubham khodiyar
shubham khodiyar 2018 年 2 月 7 日
コメント済み: Giovanni Bambini 2023 年 4 月 5 日
In my Matlab code, I am trying to merge two graphs in each iteration of for loop. I want the color of graph generated to be same for an iteration, but varying color with iteration

採用された回答

Birdman
Birdman 2018 年 2 月 7 日
One approach, notice how I used color property of plot:
x=1:10;
y=2*x;
for i=1:numel(x)
a=rand(1,3);
plot(x(i),y(i),'Marker','o','color',a);hold on;plot(x(i)+1,y(i),'Marker','o','color',a);hold on;
end
  3 件のコメント
Birdman
Birdman 2018 年 2 月 7 日
Change this line
plot(x(i),y(i),'Marker','o','color',a);hold on;plot(x(i)+1,y(i),'Marker','o','color',a);hold on;
to
plot(x(i),y(i),'Marker','o','color',a,'DisplayName',num2str(i));hold on;plot(x(i)+1,y(i),'Marker','o','color',a,'DisplayName',num2str(i));hold on;legend('show');
Giovanni Bambini
Giovanni Bambini 2023 年 4 月 5 日
Is there a way to simply save information of colors form plot, or reset the "Matlab color ordering"?

サインインしてコメントする。

その他の回答 (2 件)

Christopher Coello
Christopher Coello 2018 年 2 月 7 日
Use the property Color when you plot the figure and the colormap of your choice (parula post 2014b, jet before)
g = randn(12,150);
h = randn(12,150)+5;
figure;c_map = parula(12);
for iR = 1:12
hAx=subplot(4,3,iR);hold(hAx,'on');
plot(g(iR,:),'Color',c_map(iR,:));
plot(h(iR,:),'Color',c_map(iR,:));
end

Sree Harsha Bhimineni
Sree Harsha Bhimineni 2021 年 6 月 20 日
You can use a random function as follows:
for i=1:1:10
v = rand(3,1);
plot(X1,Y1,'Color',v);
hold on
plot(X2,Y2,'Color',v);
end

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by