Loop inside a loop isn't working
Show older comments
I am trying to create a hemisphere. But I seems like the loop inside the loop isn't working. Has somebody an idea what might be the problem?
% the values of the adjacent site
x =[-1:0.001:1];
%creating a template where I can fill in the values later on
y=zeros(2000, 2000);
% creating the highest arc (ARC A) of a hemisphere
j=0
for i=x
j=j+1;
y(j, 1000)=sqrt(1-(i^2));
end
%%
% filling in the other values, creating arcs based on the values of ARC A
for w=1:2000
H=y(w,1000) ;
L=round(H*1000);
r=1000-L;
L2=L/1000;
for xmod=-L2:0.001:L2
y(r,w)=sqrt(H^2-(xmod)^2);
r=r+1;
end
end
% plotting the matrix
surfl(y)
shading interp
I have also attached a sketch of my idea so you can imagine it better.
Accepted Answer
More Answers (1)
[X, Y, Z] = sphere;
figure
surf(X, Y, Z)
title("Full sphere")
axis square
limits = axis(gca);
figure
% Chop off the bottom half of the sphere, leaving a copy of Z unchanged so
% you can compare the two arrays Z and Z2
Z2 = Z;
Z2(Z < 0) = NaN;
surf(X, Y, Z2)
title("Half sphere")
axis equal
axis(limits)
Categories
Find more on MATLAB 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!


