フィルターのクリア

About Matrix Array Error

4 ビュー (過去 30 日間)
baby
baby 2012 年 10 月 17 日
Hello,,
before i make an example of matrix like a question
This is my example
________________________________
The number of participant : 2
What's the name : Andy
What's his/her value : A
What's the name : Juny
What's his/her value : C
________________________________
now i wanna make the number of input like this
________________________________
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
________________________________
Can someone help me how to make number of input like above?
this's my code
% Input
a= input ('The number of participant :');
for c=1:a
b(c,1)= input('What's the name ' :');
b(c,2)= input('What's his/her value ' :');
end
disp(b)
[m,n]= size (b);
before i already try with 'num2str(c)' like b(c,1)= input('What's the name ' num2str(c)' :'); but i got an error
Please help me :)

回答 (2 件)

Image Analyst
Image Analyst 2012 年 10 月 17 日
You need a cell array since they can have different lengths. Use braces instead of parentheses: b{c,1}
  2 件のコメント
baby
baby 2012 年 10 月 17 日
編集済み: baby 2012 年 10 月 17 日
u know how to make number (1) beside the text "what's the name?"
i got example from internet but when i try that in my code, i got error
this is the example
for i = 1:m
for j = 1:n
str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': '];
when i try that 'num2str(c)' i got the error :'(
Image Analyst
Image Analyst 2012 年 10 月 17 日
Use sprintf() instead.

サインインしてコメントする。


venkat vasu
venkat vasu 2012 年 10 月 17 日
Hi...
This may help you and it will take both string&character but it can store a single character.
a= input ('The number of participant :'); for c=1:a x=input('Whats the name ','s'); b(c)=x; b(c)= input('Whats his/her value '); end %%FOR DISPLAY for c=1:a disp(b(c)); disp(d(c)); end
  1 件のコメント
baby
baby 2012 年 10 月 17 日
but how about make indicator (1) beside text "What's the name?" i wanna know how to make that indicator thx u :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by