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
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 AI for Wireless에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
