for loop collecting output

2 visualizaciones (últimos 30 días)
Nikolaos Zafirakis
Nikolaos Zafirakis el 30 de Abr. de 2019
Comentada: Stephan el 30 de Abr. de 2019
F is giving me the same measurements and I can’t seem to find how to move to the next position.
A = (:,:,1) % There are 100 A symmetric matrix
for i = 1:100A
F(i) = atan(-(A(3,1)/A(3,2))) % Second A should be position (A(3,4).....
end

Respuestas (1)

Stephan
Stephan el 30 de Abr. de 2019
Editada: Stephan el 30 de Abr. de 2019
Hi,
it is not recommended to use i - since i is reserved for complex numbers. Perhaps use k or n or ii instead. I decided to use ii:
The idea is to work with the counter variable ii in this context. That means you have to find a way to express the steps of the loop by your counter variable. For example:
for ii = 1:99
F(ii) = atan(-(A(3,ii)/A(3,ii+1)))
end
would make the pairs:
ii = 1 --> A(3,1) / A(3,2)
ii = 2 --> A(3,2) / A(3,3)
ii = 3 --> A(3,3) / A(3,4)
...
ii = 99 --> A(3,99 / A(3,100)
I leave it to you to find an expression that counts the way you need it.
Best regards
Stephan
  6 comentarios
Steven Lord
Steven Lord el 30 de Abr. de 2019
I'm not certain I understand what you're trying to compute. Can you show us exactly what the results should be for the following A vector?
A = 1:9;
Stephan
Stephan el 30 de Abr. de 2019
I agree - we would need a example to be sure understanding you correctly

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by