adding a colormap('jet') to my grapgh please help me

2 ビュー (過去 30 日間)
Saleh
Saleh 2022 年 12 月 12 日
コメント済み: Saleh 2022 年 12 月 12 日
script code :
clc;
close all;
center=[0,0]; %Defining the center of circle ((origin))
%Plotting the first circle at different radius and here i choose from 1 to
%5 radiuses
for radius=1:5 % for loop, 1 to 5 making five completed circle
[x,y]=getCircle(center,radius); %Calling the function
plot(x,y,'LineWidth',4); %Plot Circle in one frame / here Linewidth is used to adjust (increase) the width of the line of the circle
axis([-6 6 -5 5]) %Defining required axis [ -x x -y y ]
title('5 Circles different radius')
grid on;
hold on;
end %end for loop
% function code:
function [x,y]=getCircle(center,radius)
t=[0:360];
x=radius*cos(t*(pi/180)); %Claculate the x axis
y=radius*sin(t*(pi/180)); %Claculate the y axis
colormap('jet'); %i added the colormap('jet') here but still no changes can u help me please
end

採用された回答

Image Analyst
Image Analyst 2022 年 12 月 12 日
You can specify the color in the call to plot():
clc;
close all;
center=[0,0]; %Defining the center of circle ((origin))
%Plotting the circles at different radius.
% Here I chose from 1 to 5 radiuses.
numRadiuses = 5;
% Get the 5 colors from the "jet" colormap.
plotColors = jet(numRadiuses);
for radius=1:numRadiuses % for loop, 1 to 5 making five completed circle
[x,y] = getCircle(center, radius); % Calling the function
fprintf('Printing circle #%d in this color : [%f, %f, %f].\n', ...
radius, plotColors(radius, 1), plotColors(radius, 2), plotColors(radius, 3));
plot(x,y, '-', 'Color', plotColors(radius, :), 'LineWidth',4); %Plot Circle in one frame / here Linewidth is used to adjust (increase) the width of the line of the circle
axis([-6 6 -5 5]) %Defining required axis [ -x x -y y ]
hold on;
end % end for loop
Printing circle #1 in this color : [0.000000, 0.500000, 1.000000]. Printing circle #2 in this color : [0.000000, 1.000000, 1.000000]. Printing circle #3 in this color : [0.500000, 1.000000, 0.500000]. Printing circle #4 in this color : [1.000000, 1.000000, 0.000000]. Printing circle #5 in this color : [1.000000, 0.500000, 0.000000].
caption = sprintf('%d Circles of different radius', numRadiuses);
title(caption)
grid on;
legend('Location', 'northwest')
% function code:
function [x,y]=getCircle(center,radius)
t = 0 : 360;
x = radius * cos(t*(pi/180)); % Calculate the x axis
y = radius * sin(t*(pi/180)); % Calculate the y axis
end
  1 件のコメント
Saleh
Saleh 2022 年 12 月 12 日
you aare the best thanks

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

その他の回答 (1 件)

Les Beckham
Les Beckham 2022 年 12 月 12 日
center=[0,0]; %Defining the center of circle ((origin))
%Plotting the first circle at different radius and here i choose from 1 to
%5 radiuses
for radius=1:5 % for loop, 1 to 5 making five completed circle
[x,y]=getCircle(center,radius); %Calling the function
plot(x,y,'LineWidth',4); %Plot Circle in one frame / here Linewidth is used to adjust (increase) the width of the line of the circle
colormap('jet'); % <<< Moved this to where it belongs
axis([-6 6 -5 5]) %Defining required axis [ -x x -y y ]
title('5 Circles different radius')
grid on;
hold on;
end %end for loop
function [x,y]=getCircle(center,radius)
t=[0:360];
x=radius*cos(t*(pi/180)); %Claculate the x axis
y=radius*sin(t*(pi/180)); %Claculate the y axis
end
  3 件のコメント
Saleh
Saleh 2022 年 12 月 12 日
so i cannot achieve it ?
Bora Eryilmaz
Bora Eryilmaz 2022 年 12 月 12 日

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by