How do I save data from a fprintf loop?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have this bit of code, that takes an input as string (usually something like 'hello'), converts it to its binary equiv and then encodes it, then outputs it using the following:
fprintf(['\nDecoded Message = %2d\n Coded: Error rate = %1.2f, ' ...
'Number of errors = %d\n'], ...
Bin(ii),errStats(1),errStats(2));
But I'm unsure how to extract the data generated from this and save it in an array, so that I can use it elsewhere.
For context here is the rest of the code it runs off:
for ii = 1:1:N
dpskdemod = comm.DPSKDemodulator(8,pi/4);
dpskdemod2 = comm.DPSKDemodulator(M);
for counter = 1:numframes
data = randi([0 1],cfgLDPCEnc.NumInformationBits,1,'int8');
% Transmit and receive with LDPC coding
encodedData = ldpcEncode(data,cfgLDPCEnc);
reshape(encodedData, 1, []);
modSignal = dpskmod(encodedData);
recievedSignal = awgn(modSignal,1);
demodSignal = dpskdemod(recievedSignal);
recievedBits = ldpcDecode(demodSignal,cfgLDPCDec,maxnumiter);
errStats = ber(data,recievedBits);
% Transmit and receive with no LDPC coding
noCoding = dpskmod2(data);
rxNoCoding = awgn(noCoding,Bin(ii));
rxBitsNoCoding = dpskdemod2(rxNoCoding);
errStatsNoCoding = ber2(data,int8(rxBitsNoCoding));
end
Thank you,
Connor
0 commentaires
Réponse acceptée
dpb
le 25 Août 2022
msgs=string(N,1);
for ii=1:N
....
msgs(ii)=compose(['\nDecoded Message = %2d\n Coded: Error rate = %1.2f, ' ...
'Number of errors = %d\n'], Bin(ii),errStats(1),errStats(2));
fprintf(msgs(ii))
end
to save the actual text itself; not clear just what you intend by " how to extract the data generated from this ".
If it's just the data itself, then a struct array might be the ticket...
for ii=1:N
....
fprintf(['\nDecoded Message = %2d\n Coded: Error rate = %1.2f, ' ...
'Number of errors = %d\n'], Bin(ii),errStats(1),errStats(2));
msgs(ii).Bin=Bin(ii);
msgs(ii).Err=errStats;
end
to save the data itself as a struct array.
8 commentaires
dpb
le 26 Août 2022
Ah...thanks for the clarification. It's easy-enough to lose sight of the forest for the trees--been there, done that, many scars to show for having done...
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur AI for Wireless dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
