input comma separated values to a matrix

I need a shove in the right direction:
How do I ask the user for some numerical values that are separated by a comma? For example "Enter the numbers, separated by a comma"
Then the user would enter "1,2,3" and these numbers would go into a matrix
Second question: There isn't a go to statement in Matlab, right?

 채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2011년 12월 2일

2 개 추천

Of course it can be done.
clear; clc;
answers = input('Enter the numbers, separated by a comma : ','s');
str = regexprep(answers,',',' ');
num = str2num(str)
And about go to statement, Matlab don't have go to statement.

댓글 수: 2

Frank
Frank 2011년 12월 2일
Many thanks. I had not idea where to start. All I have is a Matlab textbook and this forum.
Robert Cumming
Robert Cumming 2011년 12월 2일
You could also use
num = strread ( answers, '%f', 'delimiter', ',' );

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by