generate a matrix from some vectors
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have an array A0 (with 1 by n elements), representing a sample with n variables. I also have two arrays LB and UB (each with 1 by n elements) representing the lower and upper bounds for our variables.
How can I quickly generate a matrix B (2n+1 by n) from A0, LB and UB in such a way that
1. the first row is A0
2. the second row is A0 but A0(1,1) is replaced by LB(1,1)
3. the third row is A0 but A0(1,1) is replaced by UB(1,1)
4. The fourth row is A0 but A0(1,2) is replaced by LB(1,2)
5. The fifth row is A0 but A0(1,2) is replaced by UB(1,2)
6. The sixth row is A0 but A0(1,3) is replaced by LB(1,3)
7. The seventh row is A0 but A0(1,3) is replaced by UB(1,3)
8. The eights row is A0 but A0(1,4) is replaced by LB(1,4)
9. ....
0 Kommentare
Akzeptierte Antwort
Thorsten
am 31 Mär. 2017
% sample values
n = 10;
a = rand(1, n);
LB = 1:n;
UB = LB + 1;
A = repmat(a, [2*n , 1]);
idx = 1:2*n+2:2*n*n;
A(idx) = LB;
A(idx + 1) = UB;
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!