Converting user input char to an array
조회 수: 5 (최근 30일)
이전 댓글 표시
As part of my university matlab module i was assigned to do an assigment from one of 4 options. I'm on a bit of a road block, part of code is requesting the user to type in 6 numbers for a lottery game, being that this data is recorded as a char i want to convert this to a numerial array (matrix). I have tried the following with no luck.
player_numbers = input ('Please enter your number: ','s');
player_lotto_numbers = str2num(player_numbers);
댓글 수: 2
Walter Roberson
2019년 4월 20일
That code should work for a variety of input formats, including if the user puts spaces or commas between the numbers. What problem are you encountering?
답변 (1개)
madhan ravi
2019년 4월 21일
편집: madhan ravi
2019년 4월 21일
It‘s not st2sum it’s str2num(). Usually str2double() is preferred.
댓글 수: 8
Walter Roberson
2019년 4월 21일
What you posted is str2num(), which is valid.
But your error message was about str2sum() with a 'sum' instead of a 'num' . That does not exist.
The code you had posted was right.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!