How to Loop on Different SNR values in MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I Hope you are doing well,
I want to make a Loop which takes different SNR value from array or cell. and save the mat file for each SNR
How can i do that?
i have the following code
But the files are overwritting How can i avoid overwrite
for SNR=[-20,-10,0,10,20,30]
channel = helperModClassTestChannel(...
'SampleRate', fs, ...
'SNR', SNR, ...
'PathDelays', [0 1.8 3.4] / fs, ...
'AveragePathGains', [0 -2 -10], ...
'KFactor', 4, ...
'MaximumDopplerShift', 4, ...
'MaximumClockOffset', 5, ...
'CenterFrequency', 902e6)
for p=1:numFramesPerModType
% 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%s%03d_SNR",fileNameRoot,modulationTypes(modType),p,SNR));
save(fileName,"frame","label")
댓글 수: 0
채택된 답변
Voss
2022년 2월 12일
편집: Voss
2022년 2월 12일
Looks like you have it essentially right; you just need to use the decimal specifier %d (or %03d or whatever makes sense) rather than the string specifier %s in the sprintf format for the index p (and maybe some underscores for readability):
% Made up variables.
dataDirectory = '';
fileNameRoot = 'result';
modulationTypes = ["QAM" "PSK"];
modType = 1;
numFramesPerModType = 2;
for SNR=[-20,-10,0,10,20,30]
for p=1:numFramesPerModType
fileName = fullfile(dataDirectory,...
sprintf("%s_%s_%d_%03d_SNR",fileNameRoot,modulationTypes(modType),p,SNR))
end
end
The way you had it, with %s for p, the file names each contain a non-alphanumeric character (characters whose ASCII code is 1, 2, etc.). These gave me an error when using save() on my version of MATLAB, but here they seemed ok. In any case, if you want to see the value of p in the file name, use some variant of %d instead of %s.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!