How to display the result of a cycle in a single matrix of a certain size

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

Why are you setting all of z to 0 each time?
Which variable are you hoping will become 2 x 56 ?
To represent each symbol, such 1 as a 0 1 0 0 0 0 0 0.
When the input data - string, each symbol of m is displayed as above specified sequence. That is a sequence of 1 х 8 * 7 =1 х 56.
I would like to dimension a variable l had 2x56.

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

 채택된 답변

Amit
Amit 2014년 1월 19일
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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2014년 1월 18일

댓글:

2014년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by