ㅇㅇ
gogyzzz@gmail.com
2017년 9월 7일 목요일
Complex double binary to matlab converter
Complex double binary to matlab converter === [Github repository](https://github.com/gogyzzz/complex_double_binary_to_matlab) You can easily load MATLAB complex data in C++(and ArrayFire), and C++ complex data on MATLAB. The structure of binary file is 'interleave Real and Imaginary components' part, demonstrated by [MATLAB R/W COMPLEX NUMBER GUIDE](https://www.mathworks.com/examples/matlab/mw/matlab-ex14013084-write-and-read-complex-numbers) Binary data is stored as 'complex double' type. ### input data type Thus you should put data of complex double type as input(or convert to complex double) But when you use ArrayFire matrix, you can put any type of matrix. ### output data type - complex double in C++ function - c64 in Arrayfire ## References - [MATLAB R/W COMPLEX NUMBER GUIDE](https://www.mathworks.com/examples/matlab/mw/matlab-ex14013084-write-and-read-complex-numbers) - [Arrayfire - Getting Started](http://arrayfire.org/docs/gettingstarted.htm) ## example in C++ ```cpp std::vector
> a = read_complex64_binary("testmat.complex.interleaved.bin", 2, 2); int nsamples = a.size(); std::cout << "check output\n"; std::copy(a.begin(), a.end(), std::ostream_iterator
>(std::cout, "\n")); std::cout << "check output from pointer\n"; std::complex
* ptr = new std::complex
[nsamples]; memcpy(ptr, a.data(), nsamples * sizeof(std::complex
)); std::copy(&ptr[0], &ptr[nsamples], std::ostream_iterator
>(std::cout, " ")); std::cout << std::endl << std::endl; // The filename will be testmat.complex.interleaved.bin write_complex64_binary(ptr, "testmat", 2, 2); // When load binary file, you should put the full name of file. a = read_complex64_binary("A.complex.interleaved.bin", 3, 3, 3); std::copy(a.begin(), a.end(), std::ostream_iterator
>(std::cout, "\n")); delete[] ptr; ``` ## example in ArrayFire ```cpp array afmat = randn(3, 3, 3, f32); af_print(afmat); std::string realfilename = write_complex64_binary(afmat, "testmat"); std::cout << "the real file name is " << realfilename << std::endl; af_print(read_complex64_binary("A.complex.interleaved.bin", dim4(3, 3, 3, 1))); system("pause"); return 0; ```
댓글 없음:
댓글 쓰기
최근 게시물
이전 게시물
홈
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기