Effacer les filtres
Effacer les filtres

How to save mat file in Matlab

5 vues (au cours des 30 derniers jours)
Med Future
Med Future le 2 Fév 2022
Commenté : Voss le 7 Fév 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

Réponse acceptée

Voss
Voss le 2 Fév 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 commentaires
Med Future
Med Future le 2 Fév 2022
@Benjamin and how to generate the 100 file from single file generated by this code
Voss
Voss le 7 Fév 2022
This code generates 10 files. Not clear where 100 files would come from.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Reporting and Database Access dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by