How to display the result of a cycle in a single matrix of a certain size
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have a cycle:
l=[];
m=[1 0 2 3 5 7 1; 1 0 2 3 5 7 1]
for k=1:2
r=m(k,1:7);
for j=r
if j==0
z = zeros(1,8,'int8');
z(1)=1;
l=[l; z];
else
z = zeros(1,8,'int8');
z(j+1)=j;
l=[l; z];
end
end
end
Input - a 2 strings, so as to make the output results have dimension 2x7*8 = 2x56???
In current code the results output as matrix 14x8
3 commentaires
Réponse acceptée
Amit
le 19 Jan 2014
I think you are looking for something like this:
m=[1 0 2 3 5 7 1; 1 0 2 3 5 7 1];
lnew = zeros(2,56,'int8');
for k=1:2
l=[];
r=m(k,1:7);
for j=r
if j==0
z = zeros(8,1,'int8');
z(1)=1;
l=[l; z];
else
z = zeros(8,1,'int8');
z(j+1)=j;
l=[l; z];
end
end
lnew(k,:) = l;
end
note: lnew is the matrix with size 2x56
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!