Generate an array with infinite values

조회 수: 8 (최근 30일)
Matteo Breda
Matteo Breda 2015년 11월 30일
편집: Prateekshya 2024년 8월 29일
Hi, I'm wondering if is possible to generate an array that contains infinite values the values from 0+ to 1-.
Thanks in advance
  댓글 수: 2
Image Analyst
Image Analyst 2015년 11월 30일
What does that mean? Inifinitely many elements (of course not), or values that are infinite (yes, use inf)? And exactly what does "one minus" mean? Do you mean negative one (-1)? What is 0+? Do you mean open/closed ranges like [0,1[ or greater than or equal to 0 but less than (and not including) 1???
Shameer Parmar
Shameer Parmar 2015년 12월 1일
check for this command rand(3)

댓글을 달려면 로그인하십시오.

답변 (1개)

Prateekshya
Prateekshya 2024년 8월 29일
편집: Prateekshya 2024년 8월 29일
Hello Matteo,
It is not possible to generate an array consisting of infinite elements since there are storage limits. However, we have a few ways using which you can achieve the goal of generating numbers between 0 to 1.
  • Using rand():
% Define the size of the array
rows = 1;
cols = 50;
% Generate a 1x50 array of random numbers between 0 and 1
randomArray = rand(rows, cols);
% Display the array
disp(randomArray);
Instead of rand(), which uses uniform distribution, you can alternatively use randn() for normal distribution.
  • Using linspace():
% Define the number of points you want in the array
numPoints = 1e6; % For example, one million points
% Generate the array from a tiny positive number close to 0 to a number close to 1
epsilon = 1e-10; % A small number to avoid including 0 and 1
array = linspace(epsilon, 1-epsilon, numPoints);
% Display the first few and last few elements to confirm
disp(array(1:10)); % First few elements
disp(array(end-10:end)); % Last few elements
I hope this works!

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by