how can i write a code with consecutive number between 0-100 and use this values inside my code?

x = 0.05 + (0.1-0.05).*rand(10,1);
i made this code to use number x with different values but i dont want them to be random numbers. how can i write a code with consecutive number between 0-100 and use this values inside my code?

 Respuesta aceptada

Is this what you are looking for?
x = 0.05 + (0.1-0.05).*[0:1:100]';
If you also want to control from which number (from 0:100) the array should start, then may be this line of code would help.
y = 10; %change it to the starting number that you want
x = 0.05 + (0.1-0.05).*[y:1:100]';

5 comentarios

i am not sure maybe i shouldnt even use the first code and totaly change because the thing that i want to find is that i want to have x numbers (for the rest of the code) and x should be range of 0-100 and it should increase 0.5. i mean x=0, 0.5, 1, 1.5 ........ 99.5, 100 like this.
Then just use:
X = [0:0.5:100]
If it does the job then accept the answer :)

Iniciar sesión para comentar.

Más respuestas (1)

Roger J
Roger J el 21 de Jul. de 2020
Editada: Roger J el 21 de Jul. de 2020
x=0:100 % creates 101 elements from 0 to 100
y=x(12) % sets y to the value of x(12)
x = 0.05 + (0.1-0.05).*[0:100]; % do some math to the 101 values before assigning to x

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Jul. de 2020

Comentada:

el 22 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by