Read/Write Data from .dat file Problem

조회 수: 1 (최근 30일)
younes
younes 2024년 9월 2일
편집: Walter Roberson 2024년 9월 3일
Hello,
i have 2 files ".dat" containes enum values and i Read this files by using comand "readmatrix" the problem its when i want to Combine this Two files in one file by using this scripte ,show me a error:
A=readmatrix('DMIR22345.Dat');%Read first file.dat
B=readmatrix('DMIR2235.Dat');%Read sconde file.dat
C=[A;B]; %Combine 2 files
csvwrite('Data1.dat', C);% Creat New file 'Data1.dat' Contains Data of file 1 and file 2
Error: after running the scripte i have this error because the size of "A" its (15761x34) Complex double and "B" its (15794x2) double :
so to resolve the error i used this scripte:
% Assuming A has more columns than B
numColsA = size(A, 2);
numColsB = size(B, 2);
if numColsA > numColsB
B(:, end+1:numColsA) = 0; % Pad B with zeros
elseif numColsB > numColsA
A(:, end+1:numColsB) = 0; % Pad A with zeros
end
% Now concatenate
C = [A; B];
csvwrite('Data1.dat', C);
it Work but when i want to Read the file "Data1.dat" by using MDA Software to see the sgnals ,didn't work and show a Msg:
Can You Help me Guys
Thank you
  댓글 수: 3
Star Strider
Star Strider 2024년 9월 2일
‘... the size of "A" its (15761x34) Complex double and "B" its (15794x2)
There is simply no way that you can concatenate those files. I have no idea what the software expects, however consider padding it with NaN rather than zeros. Zero elements have value, NaN elements do not.
The only reference I can find for ‘MDA Software’ is: https://www.mdasoft.in/. That does not tell me anything about specific file formats it may require.
dpb
dpb 2024년 9월 2일
편집: dpb 2024년 9월 3일
"...the size of "A" its (15761x34) Complex double and "B" its (15794x2) double : "
Besides the size mismatch, the two data types are different -- one is complex and the other isn't.
Why would you think these two files should be concatenated in the first place when they are completely disparate in content as well as size?
This is absolutely nothing like the previous Q? you asked about putting together two files each of whch was two-colums of type double, just different lengths. That makes sense in at least creating one long file from two; this request simply makes no sense at all as to why one would even consider doing such a thing.
As @Star Strider notes, it cannot be done in any straightforward way, and it is, I'm sure even without knowing what MDA software is that any result you get by doing so, now matter how you force it, will NOT be anything MDA will be able to do anything with. The link to "Products" from the home page link @Star Strider is empty so what particular MDA Software product you have/want to use is anybody's guess.
In order to provide any useful help, as the barest minimum we would have to know what the target application is that you're trying to use, its expectations for input and what the two files in question represent with respect to that application reading and doing something with them.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 9월 3일
편집: Walter Roberson 2024년 9월 3일
A = readmatrix('DMIR22345.Dat');%Read first file.dat
B = readmatrix('DMIR2235.Dat');%Read sconde file.dat
filename = 'Data1.dat';
writematrix(A, filename);
writematrix(B, filename, 'WriteMode', 'append');

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by