필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Highly Challenging Problem : Delete a matrix from a binary file after reading it.

조회 수: 1 (최근 30일)
AMEHRI WALID
AMEHRI WALID 2019년 12월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello Everyone,
I want to store matrices into a binary file, the in a second time, for another process, I wan to read the matrices one-by-one from the binary file.
But, since when I read a matrix I can store it into a variable, I don't need it anymore holding memory in my binary file.
clear; clc; close; warning('off','all'); fclose('all');
delete 'All_K.bin'
% Write Part
N = 5;
n = 3;
K1 = 3*ones(N * n);
K2 = 5*ones(N * n);
K3 = 9*ones(N * n);
fileID = fopen('All_K.bin', 'a');
fwrite(fileID, K1, 'double');
fwrite(fileID, K2, 'double');
fwrite(fileID, K3, 'double');
fclose(fileID);
% Read Part
fid = fopen('All_K.bin', 'r');
% Read K1 from the file
A1 = fread(fid, [N*n N*n], 'double');
% Erase K1 from the file
% ******************************* %
% Read K2 from the file
A2 = fread(fid, [N*n N*n], 'double');
% Erase K2 from the file
% ******************************* %
% Read K3 from the file
A3 = fread(fid, [N*n N*n], 'double');
% Erase K3 from the file
% ******************************* %
fclose(fid);
So, please can Anyone help me solve this difficult problem.
Thanks in advance!
  댓글 수: 11
James Tursa
James Tursa 2019년 12월 9일
"Deleting" a section of a binary file amounts to rewriting the file, and reading/writing files to disk is one of the slowest things a computer does. Better to follow the suggestions made to avoid this. If you really need it in a raw binary form, try to read them sequentially.
AMEHRI WALID
AMEHRI WALID 2019년 12월 9일
편집: AMEHRI WALID 2019년 12월 11일
Okay, thank you everyone one for your help and your ideas.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by