gain information from a .cnv file

조회 수: 5 (최근 30일)
Richard
Richard 2012년 11월 2일
I have some data stored in a .cnv file, the data is stored as follows:
# <!-- Pressure voltage, Pressure, Strain Gauge -->
# name 0 = prSM: Pressure, Strain Gauge [db]
# name 1 = sal00: Salinity, Practical [PSU]
# name 2 = t090C: Temperature [ITS-90, deg C]
# datcnv_skipover = 0
# file_type = ascii
*END*
-0.051 0.0312 15.4328
-0.061 0.0512 15.4448
Here we have some text at the top of the .cnv file and the data stored after the string END. Each column of the data is described by name 0 for column 1, name 2 for column 1, and so on... How could I extract these names i.e. create a variable named prSM, sal00, t090C respectively? The first hurdle is to extract the variable names, I can worry about extracting the data later. Many thanks.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 2일
편집: Azzi Abdelmalek 2012년 11월 2일
fid = fopen('yourfile.cnv');
line1 = fgetl(fid);
res=line1;
while ischar(line1)
line1 = fgetl(fid);
res =char(res,line1)
end
fclose(fid);
for k=2:4;
idx1=regexp(res(k,:),'=')
idx2=regexp(res(k,:),':')
name{k-1}=res(k,idx1+1:idx2-1)
end
  댓글 수: 2
Richard
Richard 2012년 11월 2일
You've specified k = 2:4, I'm guessing this wont work for my actual data, as there are 100+ lines of text above the first line specified above, thus I was hoping of a method that used 'name0', 'name1' etc to obtain the variable name...
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 2일
편집: Azzi Abdelmalek 2012년 11월 2일
then use for k=2:100
the names are: name{1}, name{2},... .. It's better then name1 name2 ..

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by