Creating a .bin file in workspace?
조회 수: 31 (최근 30일)
이전 댓글 표시
I have to pass a .bin file to a MEX c function (zlib decompression) and I currently write to my temp folder, but I was wondering if I could create a .bin file in the workspace somehow.
By housing everything there I think I could run a parallel for loop allowing me to execute things faster.
댓글 수: 0
답변 (1개)
Deepak
2023년 6월 26일
Yes, in MATLAB, you can create a .bin file in the workspace using the `fwrite` function. Here's an example of how you can accomplish this:
% Generate some data to write to the .bin file
data = rand(1, 1000);
% Create a file in the workspace directory
filename = 'data.bin';
fileID = fopen(filename, 'w');
% Write the data to the file
fwrite(fileID, data, 'double');
% Close the file
fclose(fileID);
In this example, `data` is an array of random numbers generated using the `rand` function. The `fwrite` function is then used to write the data to the file specified by `filename`. The `'double'` argument specifies the data type to be written.
You can modify this code to suit your specific needs. Once you have created the .bin file in the workspace, you can pass it to your MEX C function for zlib decompression. Remember to adjust the file path accordingly when calling your MEX function.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!