sbit stream

5 次查看(过去 30 天)
mahaveer hanuman
mahaveer hanuman 2011-4-24
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
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
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 个评论
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by