Filter löschen
Filter löschen

How can i divide the data in rows in MATLAB

3 Ansichten (letzte 30 Tage)
Med Future
Med Future am 2 Mär. 2022
Kommentiert: Stephen23 am 2 Mär. 2022
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

Akzeptierte Antwort

Stephen23
Stephen23 am 2 Mär. 2022
Bearbeitet: Stephen23 am 2 Mär. 2022
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 Kommentare
Med Future
Med Future am 2 Mär. 2022
here is the file attached
Stephen23
Stephen23 am 2 Mär. 2022
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Arif Hoq
Arif Hoq am 2 Mär. 2022
use reshape function
A=load('newdata.mat');
dataset=A.dataset;
output=reshape(dataset,16,[]);
  8 Kommentare
Stephen23
Stephen23 am 2 Mär. 2022
Ugh, do NOT concatenate row-by-row! That is an inefficient and complex approach.
Johan
Johan am 2 Mär. 2022
I did not think you could do that with transpose, thanks for the correction

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by