Matrix Combination String and Number Inside

Hello all,
anybody knows how to make a matrix by input (not manual) with combination string and number inside?
example :
Lara 70 70
Donna 85 80
i've tried make that matrix but i just got error,,
this's my code
a= input ('Number of Participant :');
for c=1:a
b(c,1)= input ('What's your Name :','s');
b(c,2)= input ('What's your first score :');
b(c,3)= input ('What's your second score :');
end
disp(b)
i've tried anything but i just got error always,,
please help me

 채택된 답변

Kye Taylor
Kye Taylor 2012년 10월 17일

0 개 추천

A string is not the same type as a number in MATLAB. One is type char, the other is (by default) type double. To store variables of two different types in one array, you need to use cell arrays. See http://www.mathworks.com/help/matlab/matlab_prog/what-is-a-cell-array.html
Try
b{c,1} = input('What''s your Name:','s');
b{c,2} = input('What''s your first score :');
b{c,3} = input('What''s your second score :');

댓글 수: 3

baby
baby 2012년 10월 17일
Thx u :)
but do u know how to make indicator like number in input?
example :
The number of participant : 2
What's the name (1) : Andy
What's his/her value (1) : A
What's the name (2) : Juny
What's his/her value (2) : C
i want the number beside the text (ex : What's the name (1)) as indicator.
so in my example Andy is the first people and Juny is the second people.
can u help me? :)
Use the num2str function to convert the numeric iteration variable that's changing each time through the for loop to a char and construct a string to pass to the input function as follows:
for c = 1:a
str1 = ['What''s the name (',num2str(c),') :']; % build strings
str2 = ['What''s his/her value (',num2str(c),') :'];
b{c,1} = input(str1,'s');
b{c,2} = input(str2);
end
input(sprintf('What''s the name(%d):, c),'s')

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

추가 답변 (1개)

baby
baby 2012년 10월 17일

0 개 추천

Thx u Kye Taylor,,
u really the best :)
and for Walter Roberson
Thx u so much :)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2012년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by