필터 지우기
필터 지우기

problem with loading data

조회 수: 2 (최근 30일)
Olga
Olga 2011년 11월 20일
Hi!
I've got a problem with loading data (.dat files) to Matlab. I've got a file with data from rheography and ecg, but it's got specific format:
  • first 4 Byte: 00 serial number X Zo
  • 4092 Byte: data from calibration rheo and ecg (i need to load every fourth Byte, because I only need the ecg data)
  • 4 Byte: 00 serial number X Zo
  • 4092 Byte: every second Byte is ecg which is what i need to load
I've been trying to load it but all I've got is this:
"??? Error using ==> load
Number of columns on line 1 of ASCII file
C:\Users\Owu\Documents\MATLAB\program\Arek.dat
must be the same as previous lines."
Could anybody help me to find the solution how to separate ecg data from the file? I need to load it into my programe.
I'll be very geateful for your help.
  댓글 수: 1
Jan
Jan 2011년 11월 20일
@Olga: The format of the file is not clear. Please edit your question. I assume, you have to insert an empty line before the list.

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

채택된 답변

Jan
Jan 2011년 11월 20일
You cannot use load to read a binary file. FREAD is more likely to be helpful:
[EDITED]: CODE EXPANDED
FID = fopen(FileName, 'r');
if FID == -1, error('Cannot open file'); end
fread(FID, 4, 'uint8');
Data = fread(FID, [1, 4092], 'uint8');
Calib = Data(4:4:end);
fread(FID, 4, 'uint8');
Data = fread(FID, [1, 4092], 'uint8');
Value = Data(2:2:end);
I do not know, what "4B:" exactly means. But "help fread" shows all needed information to read a binary file.

추가 답변 (1개)

Olga
Olga 2011년 11월 20일
By "4B" I mean 4 bytes the .dat file I've got is built this way: first 4 bytes conteins info: 00 serial number 00 Zo, next 4092 bytes are the calibration of the signals (all I need is every fourth byte, the rest is irrelevant), next 4 bytes are like the firs four, and the rest 4092 bytes contain the information I need, but only every secont byte. I need to extract those bytes from the whole file.
  댓글 수: 4
Image Analyst
Image Analyst 2011년 11월 20일
By the way, is it every 4th byte like you said first, or is it every 2nd byte like you just said now? Either way, you change the middle value in startingIndex:4:end to be either 2 or 4 once you figure out which way it really is. By the way, are you sure the binary data is 8 bit byte data and not floating point single or double precision data? Because if it is, there would be a different args to fread().
Olga
Olga 2011년 11월 20일
Thanks Jan for your answer, it really helped. But I've got one more question consernig it: is it possible to save those variables Calib and Data in one .dat file?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by