hello everyone, i hope you are doing well.
I have dataset of shape 4x4000;
i want to divide the data in rows like each row contain 1000 samples not 4000
so output shape is 16x1000
how can i do it in matlab

 採用された回答

Stephen23
Stephen23 2022 年 3 月 2 日
編集済み: Stephen23 2022 年 3 月 2 日

0 投票

The solution is very simple: use TRANSPOSE, RESHAPE, TRANSPOSE.
Why is TRANSPOSE required? Because of the order that arrays are stored in memory: along the 1st dimension, then along the 2nd dimension, etc. You want to keep the 2nd dimension data together, so the order of the data must be changed in memory for that data to be along the 1st dimension.
S = load('newdata.mat');
dataset = S.dataset
dataset = 4×4000
1.0e+03 * 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.7626 0.7702 0.8040 0.7738 0.7793 0.7588 0.8026 0.8006 0.8427 0.8087 0.8029 0.8467 0.8443 0.8348 0.8486 0.7674 0.7618 0.8234 0.8415 0.8211 0.7879 0.7721 0.8093 0.8211 0.7871 0.8426 0.7656 0.7548 0.7711 0.8084 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000
M = reshape(dataset.',1000,16).'
M = 16×1000
1.0e+03 * 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.7626 0.7702 0.8040 0.7738 0.7793 0.7588 0.8026 0.8006 0.8427 0.8087 0.8029 0.8467 0.8443 0.8348 0.8486 0.7674 0.7618 0.8234 0.8415 0.8211 0.7879 0.7721 0.8093 0.8211 0.7871 0.8426 0.7656 0.7548 0.7711 0.8084 0.7846 0.7981 0.8113 0.8073 0.8237 0.8270 0.7569 0.7719 0.8265 0.8363 0.7623 0.8226 0.7802 0.8078 0.7655 0.8148 0.7685 0.7611 0.8208 0.7845 0.8413 0.7666 0.7983 0.8224 0.7992 0.7676 0.8490 0.8050 0.8045 0.7734

3 件のコメント

Med Future
Med Future 2022 年 3 月 2 日
@Stephen what if i have shape of 4x50000
Med Future
Med Future 2022 年 3 月 2 日
here is the file attached
Stephen23
Stephen23 2022 年 3 月 2 日
What is the expected output size?
Assuming that there are always four rows in the input data:
S = load('datset.mat');
dataset = S.dataset
dataset = 4×500000
1.0e+03 * 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.8193 0.8323 0.8458 0.7859 0.8482 0.7802 0.7997 0.7558 0.8283 0.7589 0.8391 0.7828 0.7591 0.7886 0.7876 0.8244 0.8343 0.7920 0.8022 0.7560 0.7833 0.7798 0.8335 0.7777 0.7712 0.7918 0.8324 0.8418 0.7694 0.8166 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000
M = reshape(dataset.',[],16).'
M = 16×125000
1.0e+03 * 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.8193 0.8323 0.8458 0.7859 0.8482 0.7802 0.7997 0.7558 0.8283 0.7589 0.8391 0.7828 0.7591 0.7886 0.7876 0.8244 0.8343 0.7920 0.8022 0.7560 0.7833 0.7798 0.8335 0.7777 0.7712 0.7918 0.8324 0.8418 0.7694 0.8166 0.8466 0.7681 0.8079 0.7628 0.7541 0.7825 0.8006 0.7738 0.8161 0.8286 0.7638 0.8182 0.8366 0.8349 0.7676 0.8339 0.8247 0.7974 0.8347 0.7896 0.8110 0.8293 0.8399 0.7875 0.8025 0.7613 0.7616 0.8097 0.7542 0.8173
Or a general solution for any number of input rows, where each row is split into four:
N = size(dataset,1) * 4;
M = reshape(dataset.',[],N).'
M = 16×125000
1.0e+03 * 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.4000 0.8000 1.0000 0.9000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.8193 0.8323 0.8458 0.7859 0.8482 0.7802 0.7997 0.7558 0.8283 0.7589 0.8391 0.7828 0.7591 0.7886 0.7876 0.8244 0.8343 0.7920 0.8022 0.7560 0.7833 0.7798 0.8335 0.7777 0.7712 0.7918 0.8324 0.8418 0.7694 0.8166 0.8466 0.7681 0.8079 0.7628 0.7541 0.7825 0.8006 0.7738 0.8161 0.8286 0.7638 0.8182 0.8366 0.8349 0.7676 0.8339 0.8247 0.7974 0.8347 0.7896 0.8110 0.8293 0.8399 0.7875 0.8025 0.7613 0.7616 0.8097 0.7542 0.8173

サインインしてコメントする。

その他の回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 3 月 2 日

0 投票

use reshape function
A=load('newdata.mat');
dataset=A.dataset;
output=reshape(dataset,16,[]);

8 件のコメント

Med Future
Med Future 2022 年 3 月 2 日
@Arif Hoq not like that, for example my first row contains 4000 samples
i want them in first 4 rows with shape of 1x1000
Arif Hoq
Arif Hoq 2022 年 3 月 2 日
try this one:
output=reshape(dataset,4,1000,[]);
Med Future
Med Future 2022 年 3 月 2 日
@Arif Hoq output is 4x1000x4 which is not correct
Arif Hoq
Arif Hoq 2022 年 3 月 2 日
is that ?
output=reshape(dataset,16,1,[]);
Med Future
Med Future 2022 年 3 月 2 日
@Arif Hoq not working
Johan
Johan 2022 年 3 月 2 日
If you want to concatenate row by row then you can use:
res = [];
for i = 1:size(dataset,1)
res = [res;reshape(dataset(i,:),[],1000)];
end
Stephen23
Stephen23 2022 年 3 月 2 日
Ugh, do NOT concatenate row-by-row! That is an inefficient and complex approach.
Johan
Johan 2022 年 3 月 2 日
I did not think you could do that with transpose, thanks for the correction

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 3 月 2 日

コメント済み:

2022 年 3 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by