I have a following text file delimited with 'tabs', that contains both strings and decimal numbers. I want to read only numbers in the text file and plot a surface between [T2,DEPTH,respective values] as [X,Y,Z]?

2 次查看(过去 30 天)
Hole: 123A
Top: 78.67
T2 3.34 4.26 8.16 9.84 10.01
DEPTH 0 1 2 3 4
78.67 3.38 9.28 7.86 0.00 0.00
80.52 4.68 9.27 0.00 0.00 1.24
91.50 6.66 2.34 1.23 0.00 0.00
95.67 7.88 6.88 5.43 0.00 2.34
100.01 5.44 6.54 8.23 5.01 0.00
  5 个评论
KRISHNA NISHCAL BHARATULA
This is just a part of my file. There are many rows and columns. How to read those many rows & columns where the 'FormatSpec' is changing in my data. Can you elaborate?
Thanks in Advance.
Rik
Rik 2017-3-1
There must be some structure in your data, otherwise you couldn't make sense of it either. You could count the tabs in a row to figure out how many values there are on that line and assume that's the format for the entire file.
Maybe I'll take some time tomorrow to write up some code.

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2017-3-2
fid = fopen('your data in txt file') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
%%Get positions
idx1 = find(not(cellfun('isempty',strfind(S, 'T2')))); % T2 position
idx2 = find(not(cellfun('isempty',strfind(S, 'DEPTH')))); % T2 position
idx3 = idx2:length(S) ;
%%Get the required
x = cell2mat(cellfun(@str2num,strsplit(S{idx1}),'un',0)) ;
depth = cell2mat(cellfun(@str2num,strsplit(S{idx2}),'un',0)) ;
data = cell2mat(cellfun(@str2num,S(idx3),'un',0)) ;
y = data(:,1) ;
data = data(:,2:end) ;
The above code reads your data and gives x,y,depth and respective responses. Now you can plot in the way you want.

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by