How can I turn vector to scalar?

166 visualizaciones (últimos 30 días)
Poohish
Poohish el 8 de Nov. de 2019
Comentada: Alan Weiss el 31 de Jul. de 2022
Let say the example below
x=(10,20,30,40,50,60,70)
which mean
x(1)=10;
x(2)=20;
x(3)=30;
...
x(7)=70;
How can i define the variable using loop without mentioning or defining one by one ?
As i have x(1) up to x(1155) so I can sum x(1)+x(2)+...+x(1155)

Respuestas (1)

KSSV
KSSV el 8 de Nov. de 2019
x = 10:10:70 ; % this will generate [10,20,..70] ;
sumx = sum(x) ; % this will give you sum of array
Also you can call each number from array by indexing.
for i = 1:length(x)
xi = x(i)
end
  7 comentarios
Gwen Murray
Gwen Murray el 30 de Jul. de 2022
I could really use the answer to this question if anyone found out how to do this. I am having the same exact problem in my code currently
Alan Weiss
Alan Weiss el 31 de Jul. de 2022
I suggest that you start a new question with details. I cannot understand why the previous answers suggesting to use sum are not adequate, so more detail is essential to get a helpful answer.
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by