# How to save a matrix of integers into a file using GNU Radio

**URL:** <https://www.ruby-forum.com/t/how-to-save-a-matrix-of-integers-into-a-file-using-gnu-radio/232001>\
**Category:** GNU Radio\
**Created:** [September 12, 2014, 9:22am UTC](https://www.ruby-forum.com/t/how-to-save-a-matrix-of-integers-into-a-file-using-gnu-radio/232001 "2014-09-12T09:22:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 12, 2014, 9:22am UTC](https://www.ruby-forum.com/t/how-to-save-a-matrix-of-integers-into-a-file-using-gnu-radio/232001/1 "2014-09-12T09:22:53Z")

</div>

Dear all,  
I want to save a matrix of integers into a file, similar to .mat file in  
MATLAB. To be more specific, my desire block should receive a stream of  
integers, convert it to MxN matrix and save this matrix so that I can  
get this data for further process after the flow graph stops.  
Could you give me some clue to do this in GNU Radio?  
Thank in advance,Hoang

Hoang Ngo-KhacResearch Assistant - Lab. of Signal and System, FET, UET,  
Vietnam National University-Hanoi (VNU-H)Alternative email:  
removed\_email\_address@domain.invalid, removed\_email\_address@domain.invalid:  
+84.163.682.7874

---

<div class="post-metadata">

**Author:** ![Hoang\_Ngo-Khac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/2acd7d/32.png) [@Hoang\_Ngo-Khac](https://www.ruby-forum.com/u/Hoang_Ngo-Khac)\
**Post date:** [September 12, 2014, 10:48am UTC](https://www.ruby-forum.com/t/how-to-save-a-matrix-of-integers-into-a-file-using-gnu-radio/232001/2 "2014-09-12T10:48:05Z")

</div>

In the Python domain, you have lots of tools at your disposal, such as  
Pickle (you can even use scipys io module to write .mat files if you  
like).

If you are using PMTs, you can use the metadata file sink.

M

---

<div class="post-metadata">

**Author:** ![Hoang\_Ngo-Khac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/2acd7d/32.png) [@Hoang\_Ngo-Khac](https://www.ruby-forum.com/u/Hoang_Ngo-Khac)\
**Post date:** [September 15, 2014, 10:29am UTC](https://www.ruby-forum.com/t/how-to-save-a-matrix-of-integers-into-a-file-using-gnu-radio/232001/3 "2014-09-15T10:29:30Z")

</div>

I’m not familiar with python. I’ve written a C++ block to write integers  
to a text file. I use fstream.h library. Some code in general work  
function:  
std::ofstream fw(d\_filename); unsigned char _iptr = (unsigned  
char_)input\_items[0]; if (fw.is\_open()) { for(int i =  
0; i \< noutput\_items \* d\_vlen; i++) {  
d\_data.push\_back (iptr[i]); if (((i+1)%10) == 0) fw\<\<(int)  
d\_data[i]\<\<std::endl; else fw\<\<(int) d\_data[i]\<\<" ";  
} fw.close (); } else throw  
std::runtime\_error(“Error: Can’t open file”);  
When I connect this block directly to one source clock (e.g. Vector  
Source), this block successfully captures all the input data and write  
them to text file.  
However, when I used this block at the end of a OFDM simulation flow  
graph, it only wrote very few data to the file though I keep the flow  
graph running for long time. I printed the input data in Terminal window  
and see that the data stream still flow continuously.

Hoang Ngo-KhacResearch Assistant - Lab. of Signal and System, FET, UET,  
Vietnam National University-Hanoi (VNU-H)Alternative email:  
removed\_email\_address@domain.invalid, removed\_email\_address@domain.invalid:  
+84.163.682.7874
