help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extract data from file: how to


From: Sebastian Schöps
Subject: Re: extract data from file: how to
Date: Tue, 4 Aug 2015 11:58:15 -0700 (PDT)

"Jan-Peter Schümann" wrote
> First question: how do I extract the numbers only? I played around with
> fgetl but could not succeed. 
> 
> Second question: how can I extract only those lines for which the
> z-coordinate (third column) has a value between, say, 0 and 0.05? 
> 
> Third question: which plot command is the right one to use? I suppose it
> has something to do with a 3d map plot, that right? 
> 
> Fourth question: how can I keep an empty row to separate the elements from
> each other? This is optional. 

As Juan pointed out: your data file looks suspicious. What software uses
colons and dots for decimals (e.g. -1.55E+001 -2,35E+05)? The following
Octave code could do what you want but it assumes that all colons should be
dots...

% 1st question: parse the file
data=zeros(0,10); %init data
elem=zeros(0,0); % init element pointers
fin=fopen('data.txt','r'); % open file
while ~feof(fin)
  strln = fgetl(fin); %get a line
  strln = strrep(strln, ",", "."); %replace colons
  [ln,c] = sscanf(strln,'%e %e %e %e %e %e %e %e %e %e') %try to read data 
  if (c==10) % if data was properly read
    data(end+1,:)=ln; %add a new data line
  elseif strfind(strln,"Element")  %if not data, then new element?
   elem(end+1) = size(data,1)+1; %add new element pointer
  end
end

% 2nd question: find some points based on z position
idx=find(data(:,3)>0 & data(:,3)<10)

% 3rd question: plot points in space ... 
% ... and yes, e.g. paraview is better suited for this 
scatter3(data(:,1),data(:,2),data(:,3),5,data(:,4),'filled');
colorbar;

% 4th question: where new elements start
elem

fclose(fid); %close file



--
View this message in context: 
http://octave.1599824.n4.nabble.com/extract-data-from-file-how-to-tp4671995p4672000.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]