assimble small victors into bigger one using for loop
Mostrar comentarios más antiguos
what if I have vector a1= [1; -1] and a2= [ 1 ;-1 ] and so on ... the big matrix should be like F= [ 1; 0; 1] if the size was(2) how can I do that in a for loop ?
5 comentarios
abdelrahman alhammadi
el 12 de Oct. de 2018
Walter Roberson
el 12 de Oct. de 2018
What is the rule? Is it like
A1 followed by zeros, plus
0 followed by A2 followed by zeros, plus
0 0 followed by A3 followed by zeros
And so on, with one more leading 0 for each variable?
If so are they all the same length?
Are the variables numbered consecutively and are there too many to write out by hand?
Bruno Luong
el 12 de Oct. de 2018
Editada: Bruno Luong
el 12 de Oct. de 2018
You should reply to Torsen and John on another thread, and probably better learn your lesson and FEM or learn to express clearly when ask people for help.
"what if I have vector a1 ... and a2 ... and so on ... "
then your code should be redesigned:
abdelrahman alhammadi
el 12 de Oct. de 2018
Respuestas (2)
Bruno Luong
el 12 de Oct. de 2018
a1= [1; -1];
a2= [1 ;-1];
a = {a1 a2};
F = zeros(length(a)+1,1);
for i=1:2
F(i+[0,1]) = F(i+[0,1]) + a{i};
end
Image Analyst
el 12 de Oct. de 2018
Lacking any specific and complete rules other than giving a1, a2, to use a for loop, and to give the desired F, this works:
a1 = [1; -1]
a2 = [1 ; -1]
for k = 1 : 3
F(k) = 2 - k;
end
Categorías
Más información sobre NaNs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!