필터 지우기
필터 지우기

how to read data into matlab

조회 수: 4 (최근 30일)
Wei
Wei 2011년 6월 30일
HI I have a data of this format:
0001 1111111111111101111111001111010100100000 0002 1111111111100111111010101000010000000000 0003 1111111010111100010000010100010000000000 0004 1111111111111111111111111101000001000000 I want to read the first four columns (i.e., 0001 or 0002 or 0003 or 0004) as an individual variable. For the rest, I want each column as an individual variable.
tried dlmread or load, they return me senseless data like this: dlmread('Resp_R2_T6_c1.dat','')
ans =
1.0e+039 *
0.0000 1.1111
0.0000 1.1111
Can somebody kindly show me how to read data like this?
THank you!
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 6월 30일
It's not senseless. Change the display format.
doc format

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

채택된 답변

bym
bym 2011년 7월 1일
Try this 'trick'
c = cell2mat(b);
d = c - '0'

추가 답변 (3개)

Fangjun Jiang
Fangjun Jiang 2011년 6월 30일
Maybe you can read it in as strings and then do whatever processing you want to.
>> [a,b]=textread('Resp_R2_T6_c1.dat','%s%s')
a =
'0001'
'0002'
'0003'
'0004'
b =
'1111111111111101111111001111010100100000'
'1111111111100111111010101000010000000000'
'1111111010111100010000010100010000000000'
'1111111111111111111111111101000001000000'
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2011년 7월 1일
or try
[a,b]=textread('Resp_R2_T6_c1.dat','%d%s')
Fangjun Jiang
Fangjun Jiang 2011년 7월 1일
char(b)=='0'

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


Wei
Wei 2011년 6월 30일
would you mind showing me a little bit more about the next step? Struggled with cell for a while but did not get any good luck so far. I even could not successfully convert a from string to numericals.
Many thanks!

Ian Wood
Ian Wood 2011년 7월 1일
Provided your file is in the MATLAB path, you can use importdata
data = importdata('file_name.txt')
Once you read in all of the data, you can use cell allocation to call your appropriate variables.
So if you want the first column as an individual variable (call it x), then
x = data(:,1)
assigns all of the components of the first column into the variable. Hope this helps.

카테고리

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