How to get answers to appear as an array?

10 visualizaciones (últimos 30 días)
Kyle Donk
Kyle Donk el 26 de En. de 2020
Editada: Adam Danz el 27 de En. de 2020
I have a word that I switched to ASCII code. I then used a loop to make the resulting numbers change to the numbers that I want. My question is: how would I go about making those numbers appear as an array? They currently appear as:
ans=
ans=
ans=
  3 comentarios
Kyle Donk
Kyle Donk el 27 de En. de 2020
I checked out the indexing tutorial, but all it talked about was finding certain numbers in an array that was already created.
Stephen23
Stephen23 el 27 de En. de 2020
"...but all it talked about was finding certain numbers in an array that was already created."
Which is exactly the recommended approach:

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 26 de En. de 2020
Editada: Adam Danz el 27 de En. de 2020
It looks like your outputs are being produced within a loop. Instead of displaying their values within the loop, collect the values within a vector (or cell array if the values are not all numeric scalars) and then display the final result after the loop.
See this answer for a demo (but ignore the examples using eval()).
  2 comentarios
Stephen23
Stephen23 el 27 de En. de 2020
@Adam Danz: that is a curious page to link to: surely it would make more sense to link to a page explaining indexing (of which there are plenty in the documentation), rather than a page about avoiding dynamically naming variables (something the original question does not mention anywhere).
Adam Danz
Adam Danz el 27 de En. de 2020
Editada: Adam Danz el 27 de En. de 2020
@Kyle Donk, the first two blocks of Jan's code in that answer (up voted 21x) demonstrate my suggestions. But also see Stephen's link to the Matlab documentation on preallocation.

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands 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