w= 1 0 1
w= 0 1 1
w= 0 1 0
how came this can be written in straight line
w= 1 0 1 0 1 1 0 1 0

 채택된 답변

Walter Roberson
Walter Roberson 2011년 4월 24일

0 개 추천

You might find this easier to understand:
w = []; for i = 1:30 w = [w, A(i), B(i), C(i)]; end

댓글 수: 2

Oleg Komarov
Oleg Komarov 2011년 4월 24일
Seriously :)?
Walter Roberson
Walter Roberson 2011년 4월 24일
Yup. Get it working first, and *then* optimize it.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 4월 24일

0 개 추천

It cannot. The first one assigns the row vector [0 1 0] to w, but the second one assigns a row vector of length 9 to w.
If your original data is a 3 x 3 matrix instead, then
w = reshape(w.',1,numel(w));

댓글 수: 7

mahaveer hanuman
mahaveer hanuman 2011년 4월 24일
not working
mahaveer hanuman
mahaveer hanuman 2011년 4월 24일
those 'w' are vectors
Walter Roberson
Walter Roberson 2011년 4월 24일
What *exactly* do you have for input? And what *exactly* do you want for output?
w = 1 0 1
is not valid MATLAB input.
mahaveer hanuman
mahaveer hanuman 2011년 4월 24일
for i=1:30;
w=([A(i),B(i),Q(i)]);
end
after perfoming this
i got out put as
w=
1 0 1
w=
0 0 1
w=
1 1 1
and so on.........................
now i need to make them into one single bit stream
like
w=1 0 1 0 0 1 1 1 1 .....................
Oleg Komarov
Oleg Komarov 2011년 4월 24일
Preallocate before the loop:
w = zeros(1,30*3);
for ...
w(i*3-2:i*3) = ([A(i),B(i),Q(i)]);
end
Walter Roberson
Walter Roberson 2011년 4월 24일
N = 30;
w = reshape([reshape(A(1:N),1,N); reshape(B(1:N),1,N); reshape(C(1:N),1,N)], 1, 3*N);
The above does not assume that A, B, or C are row vectors or column vectors. If the shapes are known and consistent, the code can be simplified -- especially if you are putting together _all_ of the vector instead of just a subset of it.
For example, if they are all row vectors and you are using all of them, then
w = [A;B;C]; w = w(:).';
mahaveer hanuman
mahaveer hanuman 2011년 4월 24일
thanks its working

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by