필터 지우기
필터 지우기

File import

조회 수: 2 (최근 30일)
Sami
Sami 2011년 7월 23일
Hallo,
I would like to import in Matlab a set of data, which originally is expressed in 4 columns: ex:
1490 3 2 0.
20094 1 2 0.
66779 4 2 0.
14293 3 2 0.
53990 1 2 0.
61190 4 2 0.
I want it to be imported as one column excluding the 4th columnm, and combining the 3 numbers for each row in one number like this:
1490*3*2
20094*1*2
66779*4*2
14293*3*2
53990*1*2
61190*4*2
How can I use the function textscan to do it? are there other ways to do it?
Thanks.
Sami
  댓글 수: 1
Sami
Sami 2011년 7월 23일
the stars are only to recognize the values the actual result i want is :
149032
2009412
6677942
1429332
5399012
6119042

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 7월 23일
Save your text in a file called 'test.txt'
a=importdata('test.txt');
a=a(:,1:3);
b=sprintf('%d%d%d\n',a')
c=str2num(b)
  댓글 수: 2
Sami
Sami 2011년 7월 24일
but how do I assign the path? usually i do the text import like this ...
path = 'C:\Temp\';
file = 'test.txt';
head_lines = 19;
input_file= [path file_add];
fid = fopen(input_file,'r');
data_add = textscan(fid,'%f%f%f%f','Delimiter','\t','HeaderLines', head_lines);
fclose(fid);
Sami
Sami 2011년 7월 24일
did it, thanks!

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

추가 답변 (1개)

Oleg Komarov
Oleg Komarov 2011년 7월 23일
fid = fopen('yourpath.txt');
out = textscan(fid,'%f%f%f%*f','CollectOutput',1);
out = sum(bsxfun(@times, out{1}, [100 10 1]),2);
fid = fclose(fid);

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by