Convert 1X5 to 3X3
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have a vector
a=[1 2 3 4 5]
, and I'd like to convert it to
A=[1 2 3; 2 3 4; 3 4 5]
. Any help would be appricated. Thank you!
0 Kommentare
Akzeptierte Antwort
dpb
am 8 Nov. 2020
Bearbeitet: dpb
am 9 Nov. 2020
Probably more clever ways, but
N=3; % number elements to duplicate
A=a(1:N); % first row
for i=2:numel(a)-(N-1)
A=[A;a(i:i+N-1)]; % fixed typo of N-2 prior
end
4 Kommentare
dpb
am 9 Nov. 2020
If this solved your problem, ACCEPT the answer to indicate there is a solution to others if nothing else...
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!