将数据放入矩阵
Put data into Matrix
我正在使用 Matlab,我有一个代表 5 到 55 秒采样时间的大向量,采样频率为 512 Hz,所以每个样本都是近似值。 0.0020 秒。
我想填充一个矩阵,以便每行代表 10 秒。间隔。
即第 1 行 5-15、第 2 行 15-25、第 3 行 25-35、第 4 行 35-45 和第 5 行 45-55 秒。
所以我创建了一个由 5121 个元素组成的矩阵 5,我创建了这个循环
Matrix=ones(5,5121)
tmp=1;
for row=1:5
for column=1:5121
Matrix(row,column)=t(tmp);
tmp=tmp+1;
end
end
问题是,当我转到新行时,我希望在新行中重复上一行的最后一个值。
即
5-5.0020-5.0039...15
15-15.0020 等等。
使用我创建的这个循环,我遇到了这种情况
5-5.0020-5.0039...15
15.0020-15.0039
希望你能帮助我
谢谢
n_rows = 5;
n_cols = 5121;
overlap_size = 10;
t = rand(n_rows*n_cols,1);
matrix = nan(n_rows,n_cols);
i_t = 1;
for i_row = 1 : n_rows
for i_col = 1 : n_cols
matrix(i_row,i_col) = t(i_t);
i_t=i_t+1;
end
end
matrix = [matrix(1:end-1,(end-overlap_size+1):end),matrix(2:end,:)];
当然,如果这就是全部代码,并且其中没有其他操作,这是一个更好的解决方案:
n_rows = 5;
n_cols = 5121;
overlap_size = 10;
t = rand(n_rows*n_cols,1);
matrix = reshape(t,[n_cols,n_rows])';
matrix = [matrix(1:end-1,(end-overlap_size+1):end),matrix(2:end,:)];
我正在使用 Matlab,我有一个代表 5 到 55 秒采样时间的大向量,采样频率为 512 Hz,所以每个样本都是近似值。 0.0020 秒。 我想填充一个矩阵,以便每行代表 10 秒。间隔。 即第 1 行 5-15、第 2 行 15-25、第 3 行 25-35、第 4 行 35-45 和第 5 行 45-55 秒。 所以我创建了一个由 5121 个元素组成的矩阵 5,我创建了这个循环
Matrix=ones(5,5121)
tmp=1;
for row=1:5
for column=1:5121
Matrix(row,column)=t(tmp);
tmp=tmp+1;
end
end
问题是,当我转到新行时,我希望在新行中重复上一行的最后一个值。
即
5-5.0020-5.0039...15
15-15.0020 等等。
使用我创建的这个循环,我遇到了这种情况
5-5.0020-5.0039...15
15.0020-15.0039
希望你能帮助我 谢谢
n_rows = 5;
n_cols = 5121;
overlap_size = 10;
t = rand(n_rows*n_cols,1);
matrix = nan(n_rows,n_cols);
i_t = 1;
for i_row = 1 : n_rows
for i_col = 1 : n_cols
matrix(i_row,i_col) = t(i_t);
i_t=i_t+1;
end
end
matrix = [matrix(1:end-1,(end-overlap_size+1):end),matrix(2:end,:)];
当然,如果这就是全部代码,并且其中没有其他操作,这是一个更好的解决方案:
n_rows = 5;
n_cols = 5121;
overlap_size = 10;
t = rand(n_rows*n_cols,1);
matrix = reshape(t,[n_cols,n_rows])';
matrix = [matrix(1:end-1,(end-overlap_size+1):end),matrix(2:end,:)];