Convert 1X5 to 3X3

3 Ansichten (letzte 30 Tage)
Chen Wang
Chen Wang am 8 Nov. 2020
Kommentiert: dpb am 9 Nov. 2020
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!

Akzeptierte Antwort

dpb
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
Chen Wang
Chen Wang am 9 Nov. 2020
You are awesome! Thank you so much!
dpb
dpb am 9 Nov. 2020
If this solved your problem, ACCEPT the answer to indicate there is a solution to others if nothing else...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by