如何填充同心圆的问题
请教大家一个问题,本人有一个困扰很长时间的问题:有一组同心圆,我想用矩阵[100 110 120……]来填充每个同心圆的颜色。不知道用MATLAB能否实现。谢谢!呵呵,本人用fill命令能够填充给定的颜色,但不知如何,将矩阵转换为RGB颜色并填充进去。请高手指点!在线等待……谢谢
[ 本帖最后由 ChaChing 于 2009-9-6 12:04 编辑 ] 看看这个。
xt=-pi:0.01:pi;
for R=200:-10:10;
x=R*cos(xt);
y=R*sin(xt);
plot(x,y)
axis equal
hold on
fill(x,y,*(255-R)/255)
end
谢谢楼上的兄弟,我已经自己琢磨出来了:handshake 这个是程序,没用循环直接弄的看上去比较麻烦:loveliness:
clc;
clear all;
=uigetfile('*.txt');
WJload=;
x=load(WJload);
s=x(:,1);
q1=max(x);
% q2=min(x);
s1=max(q1);
s2=1000;
S=s2/s1;
sx=x(:,2);
sx3=x(:,3);
sx4=x(:,4);
sx5=x(:,5);
sx6=x(:,6);
sx7=x(:,7);
sx8=x(:,8);
sx9=x(:,9);
sx0=x(:,10);
%éè?¨?D?μ
% w=zeros(56,1);
for k=1:length(s)
if s(k)<s2
w(k)=0;
else if s(k)/s1>S&&s(k)/s1<S+(1-S)/5
w(k)=s(k)/s1-S;
else if s(k)/s1>S+(1-S)/5&&s(k)/s1<S+(1-S)/5*2
w(k)=s(k)/s1-3/4*S;
else if s(k)/s1>S+(1-S)/5*2&&s(k)/s1<S+(1-S)/5*3
w(k)=s(k)/s1-2/4*S;
else if s(k)/s1>S+(1-S)/5*3&&s(k)/s1<S+(1-S)/5*4
w(k)=s(k)/s1-1/4*S;
else if s(k)/s1>S+(1-S)/5*4&&s(k)/s1<S+(1-S)/5*5
w(k)=s(k)/s1;
end
end
end
end
end
end
end
%°???′óD?
AA=10;
A=11;
A1=12;
A3=13;
A4=14;
A5=15;
A6=16;
A7=17;
A8=18;
A9=19;
A0=20;
N1=28;
T1=2*pi/N1;
for i=1:N1
ph=(i-1)*T1:0.01:i*T1;
x=A0*cos(ph);
y=A0*sin(ph);
X=;
Y=;
patch(X,Y,'w');
hold on;
end
phi=0:0.01:2*pi;
x=AA*cos(phi);
y=AA*sin(phi);%?2??3ì
plot(x,y);
hold on;
%éè??êy??
N=56;
step=0.05;
T=2*pi/N;
phi=0:0.01:2*pi;
x=A*cos(phi);
y=A*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A*cos(ph);
yy(i,:)=A*sin(ph);
fill(xx(i,:),yy(i,:),);
X=;
Y=[ A*sin((i-1)*T) AA*sin((i-1)*T)AA*sin(i*T)A*sin(i*T)];
patch(X,Y,,'edgecolor',);
end
%*
hold on;
for k=1:length(sx)
if sx(k)<s2
wx(k)=0;
else if sx(k)/s1>S&&sx(k)/s1<S+(1-S)/5
wx(k)=sx(k)/s1-S;
else if sx(k)/s1>S+(1-S)/5&&sx(k)/s1<S+(1-S)/5*2
wx(k)=sx(k)/s1-3/4*S;
else if sx(k)/s1>S+(1-S)/5*2&&sx(k)/s1<S+(1-S)/5*3
wx(k)=sx(k)/s1-2/4*S;
else if sx(k)/s1>S+(1-S)/5*3&&sx(k)/s1<S+(1-S)/5*4
wx(k)=sx(k)/s1-1/4*S;
else if sx(k)/s1>S+(1-S)/5*4&&sx(k)/s1<S+(1-S)/5*5
wx(k)=sx(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A1*cos(phi);
y=A1*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A1*cos(ph);
yy(i,:)=A1*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A1*sin((i-1)*T) A*sin((i-1)*T)A*sin(i*T)A1*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A*cos(phi);
y=A*sin(phi);%?2??3ì
plot(x,y);
%**
hold on;
for k=1:length(sx3)
if sx3(k)<s2
wx3(k)=0;
else if sx3(k)/s1>S&&sx3(k)/s1<S+(1-S)/5
wx3(k)=sx3(k)/s1-S;
else if sx3(k)/s1>S+(1-S)/5&&sx3(k)/s1<S+(1-S)/5*2
wx3(k)=sx3(k)/s1-3/4*S;
else if sx3(k)/s1>S+(1-S)/5*2&&sx3(k)/s1<S+(1-S)/5*3
wx3(k)=sx3(k)/s1-2/4*S;
else if sx3(k)/s1>S+(1-S)/5*3&&sx3(k)/s1<S+(1-S)/5*4
wx3(k)=sx3(k)/s1-1/4*S;
else if sx3(k)/s1>S+(1-S)/5*4&&sx3(k)/s1<S+(1-S)/5*5
wx3(k)=sx3(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A3*cos(phi);
y=A3*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A3*cos(ph);
yy(i,:)=A3*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A3*sin((i-1)*T) A1*sin((i-1)*T)A1*sin(i*T)A3*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A1*cos(phi);
y=A1*sin(phi);%?2??3ì
plot(x,y);
%***
hold on;
for k=1:length(sx)
if sx4(k)<s2
wx4(k)=0;
else if sx4(k)/s1>S&&sx4(k)/s1<S+(1-S)/5
wx4(k)=sx4(k)/s1-S;
else if sx4(k)/s1>S+(1-S)/5&&sx4(k)/s1<S+(1-S)/5*2
wx4(k)=sx4(k)/s1-3/4*S;
else if sx4(k)/s1>S+(1-S)/5*2&&sx4(k)/s1<S+(1-S)/5*3
wx4(k)=sx4(k)/s1-2/4*S;
else if sx4(k)/s1>S+(1-S)/5*3&&sx4(k)/s1<S+(1-S)/5*4
wx4(k)=sx4(k)/s1-1/4*S;
else if sx4(k)/s1>S+(1-S)/5*4&&sx4(k)/s1<S+(1-S)/5*5
wx4(k)=sx4(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A4*cos(phi);
y=A4*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A4*cos(ph);
yy(i,:)=A4*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A4*sin((i-1)*T) A3*sin((i-1)*T)A3*sin(i*T)A4*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A3*cos(phi);
y=A3*sin(phi);%?2??3ì
plot(x,y);
%***
hold on;
for k=1:length(sx)
if sx5(k)<s2
wx5(k)=0;
else if sx5(k)/s1>S&&sx5(k)/s1<S+(1-S)/5
wx5(k)=sx5(k)/s1-S;
else if sx5(k)/s1>S+(1-S)/5&&sx5(k)/s1<S+(1-S)/5*2
wx5(k)=sx5(k)/s1-3/4*S;
else if sx5(k)/s1>S+(1-S)/5*2&&sx5(k)/s1<S+(1-S)/5*3
wx5(k)=sx5(k)/s1-2/4*S;
else if sx5(k)/s1>S+(1-S)/5*3&&sx5(k)/s1<S+(1-S)/5*4
wx5(k)=sx5(k)/s1-1/4*S;
else if sx5(k)/s1>S+(1-S)/5*4&&sx5(k)/s1<S+(1-S)/5*5
wx5(k)=sx5(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A5*cos(phi);
y=A5*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A5*cos(ph);
yy(i,:)=A5*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A5*sin((i-1)*T) A4*sin((i-1)*T)A4*sin(i*T)A5*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A4*cos(phi);
y=A4*sin(phi);%?2??3ì
plot(x,y);
%****
hold on;
for k=1:length(sx)
if sx6(k)<s2
wx6(k)=0;
else if sx6(k)/s1>S&&sx6(k)/s1<S+(1-S)/5
wx6(k)=sx6(k)/s1-S;
else if sx6(k)/s1>S+(1-S)/5&&sx6(k)/s1<S+(1-S)/5*2
wx6(k)=sx6(k)/s1-3/4*S;
else if sx6(k)/s1>S+(1-S)/5*2&&sx6(k)/s1<S+(1-S)/5*3
wx6(k)=sx6(k)/s1-2/4*S;
else if sx6(k)/s1>S+(1-S)/5*3&&sx6(k)/s1<S+(1-S)/5*4
wx6(k)=sx6(k)/s1-1/4*S;
else if sx6(k)/s1>S+(1-S)/5*4&&sx6(k)/s1<S+(1-S)/5*5
wx6(k)=sx6(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A6*cos(phi);
y=A6*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A6*cos(ph);
yy(i,:)=A6*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A6*sin((i-1)*T) A5*sin((i-1)*T)A5*sin(i*T)A6*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A5*cos(phi);
y=A5*sin(phi);%?2??3ì
plot(x,y);
%***
hold on;
for k=1:length(sx)
if sx7(k)<s2
wx7(k)=0;
else if sx7(k)/s1>S&&sx7(k)/s1<S+(1-S)/5
wx7(k)=sx7(k)/s1-S;
else if sx7(k)/s1>S+(1-S)/5&&sx7(k)/s1<S+(1-S)/5*2
wx7(k)=sx7(k)/s1-3/4*S;
else if sx7(k)/s1>S+(1-S)/5*2&&sx7(k)/s1<S+(1-S)/5*3
wx7(k)=sx7(k)/s1-2/4*S;
else if sx7(k)/s1>S+(1-S)/5*3&&sx7(k)/s1<S+(1-S)/5*4
wx7(k)=sx7(k)/s1-1/4*S;
else if sx7(k)/s1>S+(1-S)/5*4&&sx7(k)/s1<S+(1-S)/5*5
wx7(k)=sx7(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A7*cos(phi);
y=A7*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A7*cos(ph);
yy(i,:)=A7*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A7*sin((i-1)*T) A6*sin((i-1)*T)A6*sin(i*T)A7*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A6*cos(phi);
y=A6*sin(phi);%?2??3ì
plot(x,y);
%*****
hold on;
for k=1:length(sx)
if sx8(k)<s2
wx8(k)=0;
else if sx8(k)/s1>S&&sx8(k)/s1<S+(1-S)/5
wx8(k)=sx8(k)/s1-S;
else if sx8(k)/s1>S+(1-S)/5&&sx8(k)/s1<S+(1-S)/5*2
wx8(k)=sx8(k)/s1-3/4*S;
else if sx8(k)/s1>S+(1-S)/5*2&&sx8(k)/s1<S+(1-S)/5*3
wx8(k)=sx8(k)/s1-2/4*S;
else if sx8(k)/s1>S+(1-S)/5*3&&sx8(k)/s1<S+(1-S)/5*4
wx8(k)=sx8(k)/s1-1/4*S;
else if sx8(k)/s1>S+(1-S)/5*4&&sx8(k)/s1<S+(1-S)/5*5
wx8(k)=sx8(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A8*cos(phi);
y=A8*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A8*cos(ph);
yy(i,:)=A8*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A8*sin((i-1)*T) A7*sin((i-1)*T)A7*sin(i*T)A8*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A7*cos(phi);
y=A7*sin(phi);%?2??3ì
plot(x,y);
%*****
hold on;
for k=1:length(sx)
if sx9(k)<s2
wx9(k)=0;
else if sx9(k)/s1>S&&sx9(k)/s1<S+(1-S)/5
wx9(k)=sx9(k)/s1-S;
else if sx9(k)/s1>S+(1-S)/5&&sx9(k)/s1<S+(1-S)/5*2
wx9(k)=sx9(k)/s1-3/4*S;
else if sx9(k)/s1>S+(1-S)/5*2&&sx9(k)/s1<S+(1-S)/5*3
wx9(k)=sx9(k)/s1-2/4*S;
else if sx9(k)/s1>S+(1-S)/5*3&&sx9(k)/s1<S+(1-S)/5*4
wx9(k)=sx9(k)/s1-1/4*S;
else if sx9(k)/s1>S+(1-S)/5*4&&sx9(k)/s1<S+(1-S)/5*5
wx9(k)=sx9(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A9*cos(phi);
y=A9*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A9*cos(ph);
yy(i,:)=A9*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A9*sin((i-1)*T) A8*sin((i-1)*T)A8*sin(i*T)A9*sin(i*T)];
patch(X1,Y1,,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A8*cos(phi);
y=A8*sin(phi);%?2??3ì
plot(x,y);
%***
hold on;
for k=1:length(sx)
if sx0(k)<s2
wx0(k)=0;
else if sx0(k)/s1>S&&s0(k)/s1<S+(1-S)/5
wx0(k)=sx0(k)/s1-S;
else if sx0(k)/s1>S+(1-S)/5&&sx0(k)/s1<S+(1-S)/5*2
wx0(k)=sx0(k)/s1-3/4*S;
else if sx0(k)/s1>S+(1-S)/5*2&&sx0(k)/s1<S+(1-S)/5*3
wx0(k)=sx0(k)/s1-2/4*S;
else if sx0(k)/s1>S+(1-S)/5*3&&sx0(k)/s1<S+(1-S)/5*4
wx0(k)=sx0(k)/s1-1/4*S;
else if sx0(k)/s1>S+(1-S)/5*4&&sx(k)/s1<S+(1-S)/5*5
wx0(k)=sx0(k)/s1;
end
end
end
end
end
end
end
T=2*pi/N;
phi=0:0.01:2*pi;
x=A0*cos(phi);
y=A0*sin(phi);%?2??3ì
plot(x,y);
hold on;
for i=1:N
ph=(i-1)*T:0.01:i*T;
xx(i,:)=A0*cos(ph);
yy(i,:)=A0*sin(ph);
fill(xx(i,:),yy(i,:),);
X1=;
Y1=[ A0*sin((i-1)*T) A9*sin((i-1)*T)A9*sin(i*T)A0*sin(i*T)];
patch(X1,Y1,'edgecolor',);
end
hold on;
phi=0:0.01:2*pi;
x=A9*cos(phi);
y=A9*sin(phi);%?2??3ì
plot(x,y);
hold on;
phi=0:0.01:2*pi;
x=A0*cos(phi);
y=A0*sin(phi);%?2??3ì
plot(x,y);
colormap(gray(64));
text(0,20.5,'起始','color','b','fontsize',8); 很好很牛,不错不错! LZ的程序不敢恭维!?:lol
页:
[1]