Clear Filters
Clear Filters

Creating a .bin file in workspace?

14 views (last 30 days)
Roman Around
Roman Around on 26 Jun 2023
Answered: Deepak on 26 Jun 2023
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.

Answers (1)

Deepak
Deepak on 26 Jun 2023
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.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!