|
|
| Author |
Message |
LarsW Active User

Joined: 23 Mar 2006
Posts: 6
Location: Lund University
|
Posted: Tue May 23, 2006 6:29 am Post subject: |
|
|
Dear Guest.
Thanks. However, I had to make some minor changes to lines 118-123 to make it run:
t = zeros(1,param.no_of_samples);
U = zeros(param.no_of_parameters,param.no_of_samples);
for p=1:param.no_of_samples %here the samples are read
t(p)=fread(fid,1,'uint')'; %time
U(:,p)=fread(fid,param.no_of_parameters,'float')'; %no_of_parameters of data
end
Best Regards
Lars |
|
| Back to top |
|
 |
McLyde Active User

Joined: 18 May 2006
Posts: 7
Location: Finland
|
Posted: Tue May 30, 2006 8:45 am Post subject: |
|
|
Thanks for this matlab-code!
Any ideas on how to make the code run faster?
This for-loop is the greatest time consumer. Would it be possible to change this for loop to some other form?
for p=1:param.no_of_samples %here the samples are read
t(p)=fread(fid,1,'uint')'; %time
U(:,p)=fread(fid,param.no_of_parameters,'float')'; %no_of_parameters of data
end |
|
| Back to top |
|
 |
McLyde Active User

Joined: 18 May 2006
Posts: 7
Location: Finland
|
Posted: Wed May 31, 2006 10:08 am Post subject: |
|
|
I've been fighting with matlab for 2 days now and got some results (finally):
function [t]=t_from_plw(fullfilename,info)
%function [U]=u_from_plw(fullfilename,info)
if nargout<1|nargout>1;error('PLW2ML needs only one [t]');end
if nargin==0;[fn,pn]=uigetfile('*.*','Open a measurement file');fullfilename=[pn,fn];info=0;end
if nargin==1;info=0;end
if fullfilename(end-3:end)~='.plw' & fullfilename(end-3:end)~='.PLW';error('PLW2ML can only open files with extension .plw or .PLW');end
fid=fopen(fullfilename); %open file for reading
if fid==-1;error('File could not be opened');end
param.header_bytes=fread(fid,1,'ushort'); %read first line of PLW-HEADER (the end of the file contains a partial explanation of how a PLW file is built up)
param.signature=char(fread(fid,40,'uchar'))'; %etc
param.version=fread(fid,1,'uint32'); %version number
if info;disp(['PLW file version ',int2str(param.version)]);end
switch param.version
case 1
antal_parametrar=50;
antal_notes=200;
case 2
antal_parametrar=50; %100;
antal_notes=200;
case 3
antal_parametrar=250;
antal_notes=1000;
case 4
antal_parametrar=250;
antal_notes=1000;
end
param.no_of_parameters=fread(fid,1,'uint32');
if info;disp(['Number of parameters ',int2str(param.no_of_parameters)]);end
param.parameters=fread(fid,antal_parametrar,'uint16'); %says 50 in PLW manual
if info;disp(['Parameters: ',int2str(param.parameters(1:param.no_of_parameters)')]);end
% param.sample_no=0;
% while param.sample_no==0
param.sample_no=fread(fid,1,'uint32'); %=following
% end
if info;disp(['Number of samples: ',int2str(param.sample_no)]);end
param.no_of_samples=fread(fid,1,'uint32'); %=previous %number of samples
if info;disp(['No OF SAMPLES: ',int2str(param.no_of_samples)]);end
param.max_samples=fread(fid,1,'uint32');
if info;disp(['MAX Number of samples: ',int2str(param.max_samples)]);end
param.interval=fread(fid,1,'uint32'); %measurement interval
if info;disp(['Interval: ',int2str(param.interval)]);end
param.interval_units=fread(fid,1,'uint16'); %interval units
if info;disp(['Interval_units: ',int2str(param.interval_units)]);end
switch param.interval_units
case 0;units=' fs';
case 1;units=' ps';
case 2;units=' ns';
case 3;units=' us';
case 4;units=' ms';
case 5;units=' s';
case 6;units=' min';
case 6;units=' h';
otherwise;units=' with unknown unit';
end
if info;disp(['Sampling interval: ',num2str(param.interval),units]);end
param.trigger_sample=fread(fid,1,'uint32');
param.triggered=fread(fid,1,'uint16');
param.first_sample=fread(fid,1,'uint32');
param.sample_bytes=fread(fid,1,'uint32');
param.settings_bytes=fread(fid,1,'uint32');
param.start_date=fread(fid,1,'uint32'); %start date (days since start of year 0)
if info;disp(['Start date (days since 1 jan year 0) ',int2str(param.start_date)]);end
param.start_time=fread(fid,1,'uint32'); %start time (seconds since start of day)
if info;disp(['Start time (secondas since beginning of day) ',int2str(param.start_time)]);end
param.minimum_time=fread(fid,1,'int32');
param.maximum_time=fread(fid,1,'int32');
param.notes=fread(fid,antal_notes,'uchar')';
param.current_time=fread(fid,1,'int32');
param.spare=fread(fid,78,'uint8');
%read DATA
t = fread(fid,inf,'int32')'; %read the data
t = t(1:2:length(t)-1); %time values can be found from t(1),t(3),t(5),...etc
t = t(1:param.no_of_samples);
%U = fread(fid,inf,'float')';
%U = U(2:2:length(U));
%U = U(1:param.no_of_samples);
-----
I now have 2 functions, the other one is called u_from_plw
The t_from_plw returns the time and u_from_plw returns one voltage parameter.
I call these 2 functions in a separate function. Someone with more experience in matlab must be able to join these two into one single function.
I have to apologize for not being able to explain this very well. But I hope someone benefits from this.  |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|