Creating a .bin file in workspace?

31 vues (au cours des 30 derniers jours)
Roman Around
Roman Around le 26 Juin 2023
Réponse apportée : Deepak le 26 Juin 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.

Réponses (1)

Deepak
Deepak le 26 Juin 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.

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by