How to make a rainbow in MatLab?
23 views (last 30 days)
Show older comments
Juan Zegarra
on 15 Apr 2019
Commented: Juan Zegarra
on 15 Apr 2019
Hello can someone please help me work this out? My professor asked us to make a rainbow. This is what I have so far, using the trajectory problem that we've been working the whole semester. The point is to make each arc of different colors (roygbiv), . What I got is just one arc with multiple colors. Please help!!!![Screen Shot 2019-04-15 at 5.40.25 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/213979/Screen%20Shot%202019-04-15%20at%205.40.25%20PM.png)
![Screen Shot 2019-04-15 at 5.40.25 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/213979/Screen%20Shot%202019-04-15%20at%205.40.25%20PM.png)
format compact
Xo=0;
Yo=0
t=0;
inch=.01;
X=0;
Y=0;
theta=45;
V=5;
g=-9.8
hold on
while X==0 | Y>0
X=Xo+V.*cosd(theta).*t;
Y=Yo+V.*sind(theta).*t+0.5.*g.*t.*t;
fprintf('t=%4.3f X=%4.2f Y=%4.3f\n',t,X,Y)
t=t+inch;
pause(0.1)
plot(X,Y,'*')
axis([0,3,0,1])
end
hold off
0 Comments
Accepted Answer
Akira Agata
on 15 Apr 2019
One possible way:
t = linspace(0,pi)';
x = cos(t);
y = sin(t);
color = jet(7);
figure
hold on
for kk = 1:7
plot((2+kk)*x,(2+kk)*y,'Color',color(kk,:),'LineWidth',20)
end
ylim([0 15])
Another possible solution:
[xGrid,yGrid] = meshgrid(-10:0.1:10,0:0.1:10);
zGrid = sqrt(xGrid.^2 + yGrid.^2);
figure
surf(xGrid,yGrid,zGrid,...
'EdgeColor', 'none',...
'FaceAlpha', 0.5)
colormap(jet)
set(gca,'CLim',[4 11])
zlim([5 10])
view(2)
I hope you enjoy these codes ! :-)
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!