MATLAB: How to get random points from upper semisphere

random

Hello eveyone,
I use this code to get random points from a sphere with radius 5:
clear all
clc
fullFileName = fullfile(pwd, 'DataPoints.txt')
% Open a text file.
fileHandle = fopen(fullFileName, 'wt');
% Write out the things we want to write out.
rng(0,'twister')
rvals = pi*rand(100,1)+pi/2;
azimuth = 2*pi*rand(100,1);
[x,y,z] = sph2cart(azimuth,rvals,5);
figure
plot3(x,y,z,'.')
axis equal
fprintf(fileHandle, '{%f, %f ,%f},',[x,y,z]');
fprintf(fileHandle, '[%f, %f ,%f],',[x,y,z]');
fprintf(fileHandle, '%f, %f , %f;',[x,y,z]');
% Close the file.
fclose(fileHandle);
% Open it in notepad (Windows OS only)
winopen(fullFileName);
, but I want to have random points from upper semisphere with this radius.
Thanks in advance.

Best Answer

Put
...
[x,y,z] = sph2cart(azimuth,rvals,5);
z = abs(z)
...