How do I save data from a fprintf loop?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
dpb
il 25 Ago 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 Commenti
dpb
il 26 Ago 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...
Più risposte (0)
Vedere anche
Categorie
Scopri di più su AI for Wireless in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
