필터 지우기
필터 지우기

How to get answers to appear as an array?

조회 수: 4 (최근 30일)
Kyle Donk
Kyle Donk 2020년 1월 26일
편집: Adam Danz 2020년 1월 27일
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
Kyle Donk
Kyle Donk 2020년 1월 27일
I checked out the indexing tutorial, but all it talked about was finding certain numbers in an array that was already created.
Stephen23
Stephen23 2020년 1월 27일
"...but all it talked about was finding certain numbers in an array that was already created."
Which is exactly the recommended approach:

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

답변 (1개)

Adam Danz
Adam Danz 2020년 1월 26일
편집: Adam Danz 2020년 1월 27일
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
Stephen23
Stephen23 2020년 1월 27일
@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 2020년 1월 27일
편집: Adam Danz 2020년 1월 27일
@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.

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

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by