How to save mat file from specific index

HI, I hope you are doing well.
I have the following Code It saves the frame as mat file name as frame8PSK001 to frame8PSK5000.
I want to save the frame starting from 8PSK5001 to So ON how can i save that
The folllowing for loop is used to save the mat files
for p=1:numFramesPerModType
How can i change the value
dataDirectory='C/NewFolder'
numFramesPerModType=5000
fileNameRoot = "frame";
% Check if data files exist
dataFilesExist = false;
if exist(dataDirectory,'dir')
files = dir(fullfile(dataDirectory,sprintf("%s*",fileNameRoot)));
if length(files) == numModulationTypes*numFramesPerModType
dataFilesExist = true;
end
end
if ~dataFilesExist
disp("Generating data and saving in data files...")
[success,msg,msgID] = mkdir(dataDirectory);
if ~success
error(msgID,msg)
end
for modType = 1:numModulationTypes
elapsedTime = seconds(toc);
elapsedTime.Format = 'hh:mm:ss';
fprintf('%s - Generating %s frames\n', ...
elapsedTime, modulationTypes(modType))
label = modulationTypes(modType);
numSymbols = (numFramesPerModType / sps);
dataSrc = helperModClassGetSourceAMC(modulationTypes(modType), sps, 2*spf, fs);
modulator = helperModClassGetModulatorAMC(modulationTypes(modType), sps, fs);
if contains(char(modulationTypes(modType)), {'B-FM','DSB-AM','SSB-AM'})
% Analog modulation types use a center frequency of 100 MHz
channel.CenterFrequency = 100e6;
else
% Digital modulation types use a center frequency of 902 MHz
channel.CenterFrequency = 902e6;
end
for p=1:numFramesPerModType
% Generate random data
x = dataSrc();
% Modulate
y = modulator(x);
% Pass through independent channels
rxSamples = channel(y);
% Remove transients from the beginning, trim to size, and normalize
frame = helperModClassFrameGenerator(rxSamples, spf, spf, transDelay, sps);
% Save data file
fileName = fullfile(dataDirectory,...
sprintf("%s%s%03d",fileNameRoot,modulationTypes(modType),p));
save(fileName,"frame","label")
end
end
else
disp("Data files exist. Skip data generation.")
end

4 Comments

Are you sure that's a good idea? Why not save all frames together in one file? The difficulty you're facing splitting them up will be encountered again when you need to read them back in.
@Matt J I just want to change the name of the files, The following loop save the frame from 001 to 5000, I just want to save with name 5001 to 10000
for p=1:numFramesPerModType:
fileName = fullfile(dataDirectory,...
sprintf("%s%s%03d",fileNameRoot,modulationTypes(modType),p));
save(fileName,"frame","label")
Are you sure that's a good idea? Why not save all frames together in one file? The difficulty you're facing splitting them up will be encountered again when you need to read them back in.
@Matt J My algo takes each frame seperatly thats why

Sign in to comment.

Answers (1)

Matt J
Matt J on 12 Feb 2022
Edited: Matt J on 12 Feb 2022
My algo takes each frame seperatly thats why
That does not disqualify keeping them all in a common .mat file. You can use matfile() to read individual sub-chunks of an array from a .mat file.

Products

Release

R2021b

Asked:

on 12 Feb 2022

Edited:

on 12 Feb 2022

Community Treasure Hunt

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

Start Hunting!