How do I save data from a fprintf loop?

7 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2022-8-25
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 个评论
Connor Baker
Connor Baker 2022-8-26
Ahhh yes! Of course!!
Sorry!!! I'm not sure what was going on. I got very confused with what I was doinh.
I do apoligise for the confusion, and thank you very much for answering and trying to work through my mess.
Much appreciated :)
dpb
dpb 2022-8-26
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...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 AI for Wireless 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by