![]() |
for循环做一个同心圆环图像时的问题
代码如下:
a=input('请输入圆心横坐标(例如 -2):'); b=input('请输入圆心纵坐标(例如 3):'); for n=1:1:10 t=linspace(-pi,pi); x=sin(t)'*sqrt(0.02*n)+a; y=cos(t)'*sqrt(0.02*n)+b; plot(x,y) axis equal end 运行结果只生成一个n=10时的圆,我的目的是生成对应n=1,2,3,,,10的10个同心圆环。向各位大侠赐教下。谢谢了:) |
回复: for循环做一个同心圆环图像时的问题
function plotcircle(n,center)
for i=1:n subplotcircle(i,center); hold on; end axis equal; function subplotcircle(r,center) t=linspace(-pi,pi,100);%%画100个点 x=cos(t)*r+center(1); y=sin(t)*r+center(2); plot(x,y) 画n个同心圆,以center为圆心 |
回复: for循环做一个同心圆环图像时的问题
看下程序可否:
a=input('请输入圆心横坐标(例如 -2):'); b=input('请输入圆心纵坐标(例如 3):'); for n=1:1:10 t=linspace(-pi,pi); x=sin(t)*sqrt(0.02*n)+a; y=cos(t)*sqrt(0.02*n)+b; plot(x,y) [COLOR="Blue"]hold on[/COLOR] axis equal end 应加hold on 否者只画出最后一个。 |
回复: fill 或patch指令填充同心圆环的问题
绘制十个同心圆:
clear;clc a=input('请输入圆心横坐标(例如 -2):'); b=input('请输入圆心纵坐标(例如 3):'); for k=1:1:10 t=linspace(-pi,pi); x=sin(t)'*sqrtm(0.02*k)+a; y=cos(t)'*sqrtm(0.02*k)+b; plot(x,y) hold on axis equal 我想用fill或patch指令将第一个圆与第二个圆之间,第三个圆与第四个圆之间,第五个圆与第六个圆之间。。。第九个圆与第十个圆之间的环带填充成黑色,这样就形成了黑白相间的环带。望高人指点一番。谢谢了 |
回复: for循环做一个同心圆环图像时的问题
a=input('请输入圆心横坐标(例如 -2):');
b=input('请输入圆心纵坐标(例如 3):'); for n=1:1:10 t=linspace(-pi,pi); x=sin(t)*sqrt(0.02*n)+a; y=cos(t)*sqrt(0.02*n)+b; plot(x,y) hold on axis equal end for n=1:2:9 t=linspace(-pi,pi); x0=sin(t)*sqrt(0.02*n)+a; x1=sin(t)*sqrt(0.02*(n+1))+a; t=x0:0.01:x1; y0=cos(t)*sqrt(0.02*n)+b; y1=cos(t)*sqrt(0.02*(n+1))+a; s=y0:0.01:y1; plot(t,s,'b') hold on end 这样应该可以了,你把那个对应于每个圆环中的点拿出来,然后绘成黑色的点图就可以了。 |
回复: for循环做一个同心圆环图像时的问题
运行代码后出现如下警告:
Warning: Colon operands must be real scalars. ??? Error using ==> plot Vectors must be the same lengths. 不知何解 |
回复: for循环做一个同心圆环图像时的问题
绘制并填充特定的十个同心圆:
clear;clc a=input('请输入圆心横坐标(例如 -2):'); b=input('请输入圆心纵坐标(例如 3):'); for k=1:1:10 t=linspace(-pi,pi); x=sin(t)'*sqrtm(0.02*k)+a; y=cos(t)'*sqrtm(0.02*k)+b; plot(x,y) hold on axis equal 我想用fill或patch指令将第一个圆与第二个圆之间,第三个圆与第四个圆之间,第五个圆与第六个圆之间。。。第九个圆与第十个圆之间的环带填充成黑色,这样就形成了黑白相间的环带。请问是否了解。谢谢了。 |
回复: for循环做一个同心圆环图像时的问题
不知下程序可否:
a=input('请输入圆心横坐标(例如 -2):'); b=input('请输入圆心纵坐标(例如 3):'); for n=10:-1:1 t=linspace(-pi,pi); x=sin(t)*sqrt(0.02*n)+a; y=cos(t)*sqrt(0.02*n)+b; if rem(n,2)==0 fill(x,y,'k'); elseif rem(n,2)==1 fill(x,y,'w') end hold on axis equal end 希望有帮助!! |
回复: for循环做一个同心圆环图像时的问题
那如果绘制的是黑白相间的条形带,设带宽横坐标为x,纵坐标为y,给定一个坐标点s(a,b),
n=10:-1:1 x=sqrt(0.02*n)+a; y任意取,该如何绘制。用bar指令好像不行吧。 |
回复: for循环做一个同心圆环图像时的问题
给定一点p(x,y),如何以它为中心画一宽高分别为a,b的矩形?最好又能对其进行填充
|
所有时间均为北京时间。现在的时间是 03:06。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.