Borrar filtros
Borrar filtros

Creating a .bin file in workspace?

14 visualizaciones (últimos 30 días)
Roman Around
Roman Around el 26 de Jun. de 2023
Respondida: Deepak el 26 de Jun. de 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.

Respuestas (1)

Deepak
Deepak el 26 de Jun. de 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.

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by