Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は次のようなデータを持っています:
data=[1 2 3 4 5 6 7 8];
次のような新しいデータ マトリックス (4 x 8) が必要です。
new_data =[ 1 2 0 0 0 0 0 0 0 0 3 4 0 0 0 0 0 0 0 0 5 6 0 0 0 0 0 0 0 0 7 8 ]
FORループを使用してそれを行う方法は? 何か助けはありますか?
forループを使用する必要はありません
data = 1:8; newdata = [reshape(data,2,4); zeros(8,4)]; newdata = reshape(newdata(1:32), 8, 4)';
必要に応じて、ループを使用するソリューションを次に示します
clear('newdata'); for ii = 1:4 index = 2*(ii-1)+1:2*ii; newdata(ii,index) = data(index); end