small problem, how i can insert srting in matix ??

how i can insert string in matrix ??
I want to do this program :
-----------------------------
%comment section
%input section
n = input('=');
%calcultion section
s1 = zeros(3,n);
for m=1:n
q = input('sub= ','s');
d = input('hour = ');
w = input('degree =');
s1(1,m) = q ;
s1(2,m) = d ;
s1(3,m) = w ;
end
disp (s1)
------------------------
I have problem in "" s1(1,m) = q ; "" because q is input for string
hou i can fix this problem ??
thinks a lot

 Réponse acceptée

Evan
Evan le 4 Déc 2012
Modifié(e) : Evan le 4 Déc 2012
If you want to create an array of mixed datatypes (e.g. numbers and strings), you'll need to use a cell array.
To do this, you would replace s1 = zeros(3,n) with:
s1 = cell(3,n);
Then you would need to reference the elements of this cell array using { } brackets instead of ( ) parentheses. So your code would look like this.
%input section
n = input('=');
% calculation section
s1 = cell(3,n);
for m = 1:n
q = input('sub= ','s');
d = input('hour = ');
w = input('degree =');
s1{1,m} = q;
s1{2,m} = d;
s1{3,m} = w;
end
disp (s1)

Plus de réponses (1)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by