Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 24 Avr 2011
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 commentaires
mahaveer hanuman
le 24 Avr 2011
mahaveer hanuman
le 24 Avr 2011
Walter Roberson
le 24 Avr 2011
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
le 24 Avr 2011
Oleg Komarov
le 24 Avr 2011
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
le 24 Avr 2011
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
le 24 Avr 2011
Catégories
En savoir plus sur Physics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!