필터 지우기
필터 지우기

Reading a file and loading in to matlab.

조회 수: 7 (최근 30일)
Raady
Raady 2016년 9월 1일
댓글: Image Analyst 2016년 9월 1일
I have downloaded a typical dataset from IMS BearingDataset (4. BearingDataset). It contains 3 folders and there are files with names like '2003.10.22.06.24' and the last 3 numbers varies. It shows the file extension as the last number(like .24 file format for the above file mentioned). I can open these files with notepad. When I open this the data is like
-0.022 -0.039 -0.183 -0.054 -0.105 -0.134 -0.129 -0.142
-0.105 -0.017 -0.164 -0.183 -0.049 0.029 -0.115 -0.122
-0.183 -0.098 -0.195 -0.125 -0.005 -0.007 -0.171 -0.071
-0.178 -0.161 -0.159 -0.178 -0.100 -0.115 -0.112 -0.078
-0.208 -0.129 -0.261 -0.098 -0.151 -0.205 -0.063 -0.066
-0.232 -0.061 -0.281 -0.125 0.046 -0.088 -0.078 -0.078
-0.112 -0.132 -0.181 -0.186 -0.132 -0.051 -0.132 -0.076
-0.054 -0.107 -0.173 -0.134 -0.164 0.002 -0.146 -0.125
-0.159 -0.032 -0.161 -0.181 -0.110 -0.044 -0.173 -0.137
-0.225 -0.044 -0.090 -0.159 -0.100 -0.151 -0.139 -0.076
-0.093 -0.117 -0.039 -0.161 -0.132 -0.161 -0.090 -0.098
-0.002 -0.161 -0.042 -0.054 -0.095 -0.232 -0.137 -0.042
0.000 -0.117 -0.081 -0.088 -0.142 -0.183 -0.117 -0.171
-0.154 -0.142 -0.027 -0.093 -0.183 -0.251 -0.095 -0.083
The columned data belongs to one bearing data . Now I want to load this in to a matrix format. Let me know how do i load this kind of file format in to matlab. I have tried using dlmread
M = dlmread('D:\Data_IMS Bearing\1st_test\2003.10.22.12.06.24');
it shows error
Error using dlmread (line 61)
The file 'D:\Data_IMS Bearing\1st_test\2003.10.22.12.06' could not be opened because: No such file or directory
Error in loadbearingdata (line 24)
M = dlmread('D:\Data_IMS Bearing\1st_test\2003.10.22.12.06.24');
I tried renaming it as txt file but even then it shows error.
Do any one know how to read these kind of files ? Thanks, Raady
  댓글 수: 7
Raady
Raady 2016년 9월 1일
편집: Raady 2016년 9월 1일
I have uploaded the sample , for a known path for this sample I want to read the contents and load data in to variable which is [no_of_rows x 8_columns] size.
per isakson
per isakson 2016년 9월 1일
편집: per isakson 2016년 9월 1일
"I want to read the contents" &nbsp Yes, but you have most likely made a typo or something, which causes the error. See @Images answer.

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

채택된 답변

Image Analyst
Image Analyst 2016년 9월 1일
It read in just fine for me. But the file you uploaded was NOT '2003.10.22.12.06.24', it was '2003.10.22.12.06.24.24'.
There are two 24's at the end of the filename, NOT just one. Make sure you're specifying the correct filename.
  댓글 수: 5
Raady
Raady 2016년 9월 1일
편집: Raady 2016년 9월 1일
Thank you for suggestions per isakson and Image analyst ! inside loop I modified as
for n = 1%:len
filename = ['D:\Data_IMS Bearing\1st_test\',G(n,:)];
M = dlmread(filename);
end
Image Analyst
Image Analyst 2016년 9월 1일
It's "safer" to use fullfile() instead of [].

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

추가 답변 (1개)

michio
michio 2016년 9월 1일
If you are working on Windows system, I am guessing you can rename all the files to *.txt using the following command
system('ren ????.??.??.??.??.?? ????.??.??.??.??.??.txt')
Then the following would do the job.
M = dlmread('1st_test\2003.10.22.12.06.24.txt');
If you are using R2014b or newer, I'd suggest you use datastore instead. It could make your code simpler. For example,
ds = datastore('1st_test\*.txt','Whitespace',' \b','Delimiter','\t');
ds.ReadSize = 'file';
ds.VariableNames = {'B1x','B1y','B2x','B2y','B3x','B3y','B4x','B4y'};
data = read(ds);
read(ds) will read in the first file.
ds.SelectedVariableNames = {'B1x'};
allB1xdata = readall(ds);
will read the fist column from all files in the folder "1st_test".
  댓글 수: 2
Raady
Raady 2016년 9월 1일
편집: Raady 2016년 9월 1일
Michio Inoue: I cannot rename it as txt file either. I have updated with a sample in my Question attachments.
michio
michio 2016년 9월 1일
It seems that the variable "filename" of your code only holds the name of the file.
dlmread(filename);
is, for example, executing
dlmread('2003.10.22.12.06.24');
I'm not sure what is your current directory is, but how's
dlmread(['D:\Data_IMS Bearing\1st_test', filename]);
instead.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by