Filter löschen
Filter löschen

How to save mat file in Matlab

5 Ansichten (letzte 30 Tage)
Med Future
Med Future am 2 Feb. 2022
Kommentiert: Voss am 7 Feb. 2022
Hi all, i hope you are doing well, i have the dataset file of shape 9920x1
i modify the mat file and want to save each mat files with shape of 1024x1 in folder How can i do that?
and generate 100 mat file from a single mat file

Akzeptierte Antwort

Voss
Voss am 2 Feb. 2022
This will generate 10 mat files, 9 of which contain a 1024x1 variable of contiguous samples from your original mat file and 1 of which contains the remaining 704 samples:
fn = '64qam12';
S = load([fn '.mat']);
block = 1024;
N = ceil(numel(S.var5)/block);
for i = 1:N
var5 = S.var5((i-1)*block+1:min(i*block,end));
save(sprintf('%s_%d.mat',fn,i),'var5');
end
Alternatively, this wil save 10 mat files, each of which contains a 1024x1 matrix, the last of which is padded with NaNs on the end:
fn = '64qam12';
S = load([fn '.mat']);
block = 1024;
N = ceil(numel(S.var5)/block);
S.var5 = [S.var5; NaN(N*block-numel(S.var5),1)];
for i = 1:N
var5 = S.var5((i-1)*block+1:i*block);
save(sprintf('%s_%d.mat',fn,i),'var5');
end
  3 Kommentare
Med Future
Med Future am 2 Feb. 2022
@Benjamin and how to generate the 100 file from single file generated by this code
Voss
Voss am 7 Feb. 2022
This code generates 10 files. Not clear where 100 files would come from.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Reporting and Database Access 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