WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Problem beim einlesen von Dateien.

 

qwertz123
Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 02.03.2012, 09:17     Titel: Problem beim einlesen von Dateien.
  Antworten mit Zitat      
Hallo zusammen ich habe von einem Arbeitskollegen zwei Dateien zum einlesen von .pts-Dateien bekommen allerdings funktioniert der Code bei mir nicht richtig es treten immer folgende fehler auf.

??? Undefined function or method 'txt2mat_01' for input arguments of type 'char'.

Error in ==> read_PTS at 18
[EM,ffn,nh,SR,hl,fpos,cell2delete]= txt2mat_01(EingabeDatei, 1, 'RowRange', [1,1e6], 'FilePos', fpos);

Error in ==> plotProfile at 14
ProfilDaten= read_PTS(char(EingabeDatei));


ich verstehe den aufbau allgemein auch noch nicht! Könnte mir vielleicht jemand was dazu erklären.

Hier der Code der ersten Datei:

Code:

[files, path]= uigetfile('MultiSelect', 'on');
[o, AnzFiles]= size(files);

for j=1:AnzFiles
   
    EingabeDatei= strcat(path, files(:,j));
    ProfilDaten= read_PTS(char(EingabeDatei));
   
    MittelStation= mean(ProfilDaten(:,2));
    str_MittelStation= num2str(MittelStation, '%5.1f');
   
    figure(j);
    hold on;
    axis square;
    axis([199 205 798 807]);
    rectangle('Position', [199.5, 803.2, 4, 2.2], 'LineWidth', 2.5, 'LineStyle','-', 'EdgeColor', [0.2784 0.5843 0.8353]);
    rectangle('Position', [202.3, 798.6, 1.0, 3.7], 'LineWidth', 2.5, 'LineStyle','-', 'EdgeColor', [0.2784 0.5843 0.8353]);
    scatter(ProfilDaten(:,1), ProfilDaten(:,3), 2, 'r', 'filled');
    grid on;
    xlabel('y-Wert', 'FontWeight','bold');
    ylabel('z-Wert', 'FontWeight','bold');
    TitelLeiste= ['VertikalProfil ', str_MittelStation, 'm'];
    title(TitelLeiste, 'FontWeight', 'bold', 'FontSize',11);
   
    M(j)= getframe(gcf);
end

movie2avi(M, 'test.avi', 'compression', 'None', 'fps', 3, 'quality', 100);
 


Code der zweiten Datei:

Code:

function EM= read_PTS(EingabeDatei)


%% Initialisierung

fpos=0;
ende= 1;
EM= NaN;

%% Programmdurchlauf

% Textdatei laden

while numel(EM) > 0
    [EM,ffn,nh,SR,hl,fpos,cell2delete]= txt2mat_01(EingabeDatei, 1, 'RowRange', [1,1e6], 'FilePos', fpos);

    % Zeilen mit Anzahl Punkten löschen
    if isnan(cell2delete(1,1)) == 0  && cell2delete(1,1) ~= 999
        [zeilen, spalten]= size(cell2delete);
        vektor= (0:1:zeilen)';
        for i=1:zeilen
            EM(cell2delete(i,1)-vektor(i,1),:)= [];
        end
    end
end
   

    % EM neu schreiben
    [zeilen1, spalten1]= size(EM);
   
    EM= EM;
 


würde mich echt freuen wenn mir jemand weiter helfen kann hier noch ein beispiel wie die dateien aufgebaut sind.

161 d
203.046383 503.464138 799.489789 -1621
203.046238 503.459892 799.478188 -1640
203.046255 503.460652 799.466928 -1640
203.046248 503.460634 799.455606 -1639
203.008609 503.646414 798.839107 -1340
203.008547 503.644811 798.827691 -1320
235412353 d
203.046248 503.460634 799.455606 -1639
203.008609 503.646414 798.839107 -1340
203.008547 503.644811 798.827691 -1320


Danke schon mal.
Private Nachricht senden Benutzer-Profile anzeigen


n.force
Forum-Century

Forum-Century


Beiträge: 118
Anmeldedatum: 02.03.12
Wohnort: nähe Magdeburg
Version: ---
     Beitrag Verfasst am: 02.03.2012, 12:31     Titel:
  Antworten mit Zitat      
Hallo,

sind das die kompletten Quellcodes? Wenn ja, fehlt die Definition der Funktion :

Code:

txt2mat_01()
 


Dein Kollege hat also irgendwo diese Funktion definiert. Und da, laut deinem Code, auf diese zugegriffen wird (Matlab diese aber nicht findet) bekommst du eine Fehlermeldung.
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 02.03.2012, 12:47     Titel:
  Antworten mit Zitat      
Also das ist der ganze Code.

Also müsste er auf seinen Rechner noch ein M-File haben mit den namen txt2mat_01() ??
Private Nachricht senden Benutzer-Profile anzeigen
 
n.force
Forum-Century

Forum-Century


Beiträge: 118
Anmeldedatum: 02.03.12
Wohnort: nähe Magdeburg
Version: ---
     Beitrag Verfasst am: 02.03.2012, 12:57     Titel:
  Antworten mit Zitat      
Das nehme ich stark an....

Es könnte sich aber auch um einen Schreibfehler handeln. Versuch mal bitte aus txt2mat_01 --> txt2mat zu machen. Es gibt nämlich den Befehl txt2mat...
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 02.03.2012, 13:15     Titel:
  Antworten mit Zitat      
geht auch nicht kommt der selber fehler code. Dann muss ich Ihn noch mal ansprechen ist leider nicht im Büro.
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.03.2012, 11:48     Titel:
  Antworten mit Zitat      
nun habe ich die datei. Aber promt kommen neue fehler!

??? Error using ==> txt2mat_01>argincheck at 1704
txt2mat_01: no such file or directory.

Error in ==> txt2mat_01 at 350
ia = argincheck(varargin);

Error in ==> read_PTS at 18
[EM,ffn,nh,SR,hl,fpos,cell2delete]= txt2mat_01(EingabeDatei, 1, 'RowRange', [1,1e6], 'FilePos', fpos);

Error in ==> plotProfile at 14
ProfilDaten= read_PTS(EingabeDatei);

Code:

%% Definitions
spuint   = uint8(32);   % Space

% find out matlab version as a decimal, up to the second dot:
v = ver('matlab');
vs= v.Version;
vsDotPos = [strfind(vs,'.'), Inf, Inf];
vn= str2double(vs(1:min(numel(vs),vsDotPos(2)-1)));

idc_less_data= 999;

%% Check input arguments

ia = argincheck(varargin);

% unwrap input argument information
is_argin_num_header   = ia.is_argin_num_header;
num_header            = ia.num_header;
is_argin_num_colon    = ia.is_argin_num_colon;
num_colon             = ia.num_colon;
conv_str             = ia.conv_str;
sr_input_ca           = ia.sr_input_ca;
num_sr                = ia.num_sr;
kl_input_ca         = ia.kl_input_ca;
num_kl              = ia.num_kl;
replace_expr        = ia.replace_expr;
num_er              = ia.num_er;
idx_rng             = ia.idx_rng;
ldx_rng             = ia.ldx_rng;
infolvl             = ia.infolvl;
is_argin_readmode   = ia.is_argin_readmode;
readmode            = ia.readmode;
numerictype         = ia.numerictype;
is_argin_rowrange   = ia.is_argin_rowrange;
rowrange            = ia.rowrange;
filepos             = ia.filepos;
is_argin_filepos    = ia.is_argin_filepos;
replace_regex       = ia.replace_regex;
num_rr              = ia.num_rr;
ffn                 = ia.ffn;
ffn_short           = ia.ffn_short;

clear varargin ia

%% Analyse data format

% try some automatic data format analysis if needed (by function anatxt)
if ~all([is_argin_num_header, is_argin_num_colon]) %, is_argin_conv_str]); % commented out as so far anatxt's conv_str is only '%f'
    % call subfunction anatxt:
    [ffn, ana_num_header, ana_num_colon, ana_conv_str, ana_sr_input_ca,...
        ana_rm, num_ali, ana_hl, ferrmsg] = anatxt(ffn,filepos,sr_input_ca,replace_expr,replace_regex,kl_input_ca,num_header);
    % accept required results from anatxt:
    if ~is_argin_num_header
        num_header = ana_num_header;
    end
    if ~is_argin_num_colon
        num_colon = ana_num_colon;
    end
    %if ~is_argin_conv_str      
    %    conv_str = ana_conv_str;
    %end
    if ~is_argin_readmode
        readmode = ana_rm;
    end
    % add new replacement strings from anatxt:
    is_new_sr   = ~ismember(ana_sr_input_ca, sr_input_ca);
    num_sr      = num_sr + sum(is_new_sr);
    sr_input_ca = [sr_input_ca,ana_sr_input_ca(is_new_sr)];
    % display information:
    if infolvl >= 1
        disp(repmat('*',1,length(ffn)+2));
        disp(['* ' ffn]);
        if numel(ferrmsg)==0
            sr_display_str = '';
            for idx = 1:num_sr;
                sr_display_str = [sr_display_str ' »' sr_input_ca{idx} '«']; %#ok<AGROW>
            end
            disp(['* read mode: ' readmode]);
            disp(['* ' num2str(num_ali)    ' data lines analysed' ]);
            disp(['* ' num2str(num_header) ' header line(s)']);
            disp(['* ' num2str(num_colon)  ' data column(s)']);
            disp(['* ' num2str(num_sr)     ' string replacement(s)' sr_display_str]);
        else
            disp(['* fread error: ' ferrmsg]);
        end
        disp(repmat('*',1,length(ffn)+2));
    end % if
   
    % return if anatxt did not detect valid data
    if ana_num_colon==0
        A = [];
        hl = '';
        fpos = filepos;
        return
    end
end

%% Detect line termination character

% www.editpadpro.com/tricklinebreak.html :
% Line Breaks in Windows, UNIX & Macintosh Text Files
% A problem that often bites people working with different platforms, such
% as a PC running Windows and a web server running Linux, is the different
% character codes used to terminate lines in text files.
%
% Windows, and DOS before it, uses a pair of CR and LF characters to
% terminate lines. UNIX (Including Linux and FreeBSD) uses an LF character
% only. The Apple Macintosh, finally, uses a CR character only. In other
% words: a complete mess.

if infolvl >= 1
    hw = waitbar(0,'detect line termination character ...');
    set(hw,'Name',[mfilename ' - ' ffn_short]);
end

lbfull = detect_line_break_characters(ffn);
% DETECT_LINE_BREAK_CHARACTERS find out type of line termination of a file
%
% lb = detect_line_break_characters(ffn)
%
% with
%   ffn     ascii file name
%   lb      line break character(s) as uint8, i.e.
%           [13 10]     (cr+lf) for standard DOS / Windows files
%           [10]        (lf) for Unix files
%           [13]        (cr) for Mac files
%
% The DOS style values are returned as defaults if no such line breaks are
% found.

lbuint = lbfull(end);          
num_lbfull = numel(lbfull);    

%% Read in ASCII file. Case 1: Portions only, as RowRange is given
% RowRange should be given if file is too huge to be read at once by fread.
% In this case consecutive freads are used.
% A line begins with its first character and ends with its last termination
% character.

if infolvl >= 1
    waitbar(0.0,hw,'reading file ...');
end

logfid = fopen(ffn);
if is_argin_filepos
    fseek(logfid,filepos,'bof');
end

if is_argin_rowrange
    do_read             = true;     % loop condition
    num_lb_prev         = 0;
    read_len            = idx_rng;
    f8                  = [];
    fposhdr             = 0;
    while do_read
        [f8p,lenf8p]  = fread(logfid,read_len,'*uint8');         % current text section

        ldcp_curr       = find(f8p==lbuint);            % line break positions in current text section
        num_lb_curr     = numel(ldcp_curr);

        % to add all header lines to f8
        if num_lb_prev < num_header                 % not all header lines were read at the end of the prev. loop => add more text to f8
            if num_header>num_lb_curr+num_lb_prev   % header even ends beyond current section
                hdx = lenf8p;                       % end index is length of section => add the whole section to f8
            else                                            % header ends within current section
                num_lines_to_add = num_header-num_lb_prev;  % how many lines to add
                hdx = ldcp_curr(num_lines_to_add);          % corresponding end index
            end
            f8 = [f8; f8p(1:hdx)]; %#ok<AGROW>
            fpos = ftell(logfid)-lenf8p+hdx;        % position of latest used character
            fposhdr = fpos-filepos;                 % index of end of header in f8
        end

        % to add lines of interest to f8
        if (num_lb_prev < num_header+rowrange(2)) && (num_lb_prev+num_lb_curr >= num_header+rowrange(1)-1)

            if num_header+rowrange(1)-1<=num_lb_prev            % lines of interest started before current section
                sdx = 1;                                        % start index is beginning of section => the part of the section to add to f8 includes the start of the section
            else                                                % lines of interest start within current section
                num_lines_to_omit = num_header+rowrange(1)-1-num_lb_prev; % how many lines not to add
                sdx = ldcp_curr(num_lines_to_omit)+1;                     % start right after the omitted lines
            end

            if num_header+rowrange(2)>num_lb_curr+num_lb_prev   % lines of interest even end beyond current section
                edx = lenf8p;                                   % end index is length of section => the part of the section to add to f8 includes the end of the section
            else                                                % lines of interest end within current section
                num_lines_to_add = num_header+rowrange(2)-num_lb_prev;  % how many lines to add
                edx = ldcp_curr(num_lines_to_add);                      % corresponding end index
            end

            f8 = [f8; f8p(sdx:edx)]; %#ok<AGROW>
            fpos = ftell(logfid)-lenf8p+edx;       % position of latest used character
        end

        % quit loop if all rows of interest are read or if end of file is reached
        if num_lb_prev >= num_header+rowrange(2) || lenf8p<read_len
            do_read = false;
        end
        num_lb_prev          = num_lb_prev + num_lb_curr;    % absolute number of dectected line breaks
    end
   
    hl = char(f8(1:fposhdr)');
end
%% Read in ASCII file. Case 2: Full file

if ~is_argin_rowrange
    [f8,fpos]  = fread(logfid,Inf,'*uint8'); % das Einlesen

    % simply read header with fgetl
    hl = '';
    if num_header > 0
        fseek(logfid, 0, 'bof');
        for i = 1:num_header
            hl = [hl, fgetl(logfid), char(lbfull)]; %#ok<AGROW>
        end
    end
end

if ftell(logfid) == -1
    error(ferror(fid, 'clear'));
end

fclose(logfid);

if numel(f8)==0
    A = [];
    close(hw)
    return
end


%% Clean up trailing whitespaces
% replace all trailing whitespaces by spaces and a linebreak
% (quick&dirty)

if infolvl >= 1
    waitbar(0.0,hw,'cleaning up whitespaces ...');
end
cnt_trail_white = 0;
is_ws_at_end = true;

while is_ws_at_end  % step through the endmost characters
    if f8(end-cnt_trail_white) <= spuint        % is it a whitespace?
        cnt_trail_white = cnt_trail_white + 1;
    else
        f8(end-cnt_trail_white+1:end) = spuint;   % fill with spaces
        if cnt_trail_white >= num_lbfull
            f8(end-num_lbfull+(1:num_lbfull))  = lbfull;    %#ok<AGROW> % replace endmost space(s) by a line break
        else
            f8(end+(1:num_lbfull))  = lbfull;               %#ok<AGROW> % append a final line break
        end
        is_ws_at_end = false;
    end
end % while


%% Find linebreak indices and bad line positions
% In what follows the text will repeatedly be processed in consecutive
% sections of length <idx_rng> to help avoid memory problems.

lenf8 = numel(f8);
idx_lo   = 1;   % init., start index of a section processed in a loop
lf_idc   = 0;   % init., will contain the line break indices
kl_idc   = [];  % init., will contain the indices of bad line markers strings
while idx_lo < lenf8
    if infolvl >= 1
        waitbar(0.25*(idx_lo/lenf8),hw,'finding line breaks ...');
    end
    idx_hi = min(idx_lo - 1 + idx_rng,lenf8);   % end index of current section
   
    % Check for possible bad line markers and find line breaks
    if num_kl>0
        f8_akt = f8(idx_lo:idx_hi);            % current working section
        for idx = 1:num_kl                      % find positions of all markers
            %kl_idx_akt = findstr(kl_input_ca{idx},char(f8_akt'))';
            kl_idx_akt = strfind(char(f8_akt'),kl_input_ca{idx})'; % todo
            kl_tdc = [kl_idc; kl_idx_akt + idx_lo-1];
            kl_idc = kl_tdc;
        end % for
        islb   = f8_akt==lbuint;
    else
        islb   = f8(idx_lo:idx_hi)==lbuint;
    end
   
    % collect line break indices
    lf_tdc = [lf_idc; find(islb)+idx_lo-1]; % use lf_tdc temporarily to ...
    lf_idc = lf_tdc;                        % avoid memory fragmentation (?)
    idx_lo = idx_hi + 1;                    % start index for the following loop
   
end % while
num_lf = numel(lf_idc);
clear lf_tdc islb f8_akt kl_tdc


%% Delete rows marked as bad

% Have we found bad line markers?
if ~isempty(kl_idc)
    if infolvl >= 1
        waitbar(0.25,hw,'deleting rows ...');
    end

    % find indices of line breaks bordering a marker
   [L,R] = neighbours(kl_idc, lf_idc);
   
    % care for multiple markers within a single row
    if any(diff(L) <= 0) && any(diff(R) <= 0)
        L = unique(L);
        R = unique(R);
    end
   
    % delete the bad rows
    f8 = cutvec(f8,L+1,R,false);
   
    % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    % update line break indices (same as above - are there better ways?)
    lenf8 = numel(f8);
    idx_lo   = 1;   % init., start index of a section processed in a loop
    lf_idc   = 0;   % init., will contain the line break indices
    while idx_lo < lenf8
        idx_hi = min(idx_lo - 1 + idx_rng,lenf8);       % end index of current section
        f8_akt = f8(idx_lo:idx_hi);                     % current working section  
        islb   = f8_akt==lbuint;
        lf_tdc = [lf_idc; find(islb)+idx_lo-1];         % use lf_tdc temporarily to ...
        lf_idc = lf_tdc;                                % avoid memory fragmentation (?)
        idx_lo = idx_hi + 1;                            % start index for the following loop
    end % while
    num_lf = numel(lf_idc);
    clear lf_tdc islb f8_akt
    % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
end % if
clear L R kl_idc


%% Replace (regular) expressions and characters

f8=char(f8);                % quicker with strrep, required by sscanf

if num_rr > 0
    has_length_changed = true;
else
    has_length_changed = false; % flag for changes of length of f8 by replacements
end

if any([num_sr,num_er,num_rr] > 0 )
    if infolvl >= 1
        waitbar(0.25,hw,'replacing strings ...');
    end

    ldx_lo = num_header+1;                                  % start index
    while ldx_lo < num_lf
        ldx_hi = min(ldx_lo - 1 + ldx_rng,num_lf);          % end index
        f8_akt = f8( lf_idc(ldx_lo)+1:lf_idc(ldx_hi))';       % current working section

       
        if num_er > 0 || num_rr > 0
            len_f8_akt = (lf_idc(ldx_hi))-(lf_idc(ldx_lo));     % length of current section before replacements

            % Replacements, e.g. {'odd','one','1'} replaces 'odd' and 'one' by '1'

            % Regular Expression Replacements: ============================
            for vdx = 1:num_rr                  % step throug replacements arguments
                srarg = replace_regex{vdx};       % pick a single argument...

                for sdx = 1:(numel(srarg)-1)
                    f8_akt = regexprep(f8_akt, srarg{sdx}, srarg{end});    % ... and perform replacements
                end % for

            end % for

            % Expression Replacements: ====================================
            for vdx = 1:num_er                  % step throug replacements arguments
                srarg = replace_expr{vdx};       % pick a single argument...

                for sdx = 1:(numel(srarg)-1)
                    f8_akt = strrep(f8_akt, srarg{sdx}, srarg{end});    % ... and perform replacements
                    if ~has_length_changed && (len_f8_akt~=numel(f8_akt))
                        has_length_changed = true;                      % detect a change of length of f8
                    end
                end % for

            end % for

            % update f8-sections by f8_akt ================================
            exten = numel(f8_akt) - len_f8_akt;   % extension by replacements
            if exten == 0  
                f8( lf_idc(ldx_lo)+1:lf_idc(ldx_hi)) = f8_akt';
            else            
                f8 = [f8(1:lf_idc(ldx_lo)); f8_akt'; f8(lf_idc(ldx_hi)+1:end)];
                % update linebreak indices of the following sections
                % (but we don't know the lb indices of the current one anymore):
                lf_idc(ldx_hi:end) = lf_idc(ldx_hi:end) + exten;
            end
           
        end % if num_er > 0 || num_rr > 0
       
        % Character Replacements: =========================================
        for vdx = 1:num_sr                  % step through replacement arguments
            srarg = sr_input_ca{vdx};       % pick a single argument
            for sdx = 1:(numel(srarg)-1)
                rep_idx = lf_idc(ldx_lo)+strfind(f8_akt,srarg(sdx));
                f8(rep_idx) = srarg(end);   % perform replacement
            end % for
        end
       
        ldx_lo = ldx_hi; % start index for the following loop
        if infolvl >= 1
            waitbar(0.25+0.23*(idx_lo/lenf8),hw)
        end
    end % while

    clear f8_akt
end % if

%% Update linebreak indices
% see above...

if has_length_changed
    if infolvl >= 1
        waitbar(0.48,hw,'finding new line breaks ...')
    end
    f8=uint8(f8);
    lenf8 = numel(f8);
    idx_lo   = 1;  
    lf_idc   = 0;  
    while idx_lo < lenf8
        idx_hi = min(idx_lo - 1 + idx_rng,lenf8);      
        f8_akt = f8(idx_lo:idx_hi);                      
        islb   = f8_akt==lbuint;
        lf_tdc = [lf_idc; find(islb)+idx_lo-1];        
        lf_idc = lf_tdc;                                
        idx_lo = idx_hi + 1;    
    end % while
    num_lf = numel(lf_idc);
    clear lf_tdc islb f8_akt
    f8=char(f8);
end


%% Try converting large sections (ReadMode 'Matrix')
% sscanf will be applied to consecutive working sections consisting of
% <ldx_rng> rows. The number of numeric values must then be a multiple of
% the number of columns. Otherwise, or if sscanf produces an error, inform
% the user and eventually proceed to the (slower) line-by-line conversion.

errmsg = '';    % Init. error message variable
if strcmpi(readmode,'auto') || strcmpi(readmode,'matrix')
    if infolvl >= 1
        waitbar(0.5,hw,'converting large bites ...');
    end
    f8=char(f8);
    if vn>=7
        lf_idc = uint32(lf_idc);    % to save memory...
    end
    try
        % initialize result matrix A depending on matlab version:
        if vn>=7
            A = zeros(num_lf-num_header-1,num_colon,numerictype);
        else
            % create a single row of A to be repeated if numerictype is
            % other than double:
            Ar= zeros(1,num_colon);
            switch lower(numerictype)
                case 'double'
                    A = zeros(num_lf-num_header-1,num_colon);
                case 'single'
                    A = repmat(single(Ar),num_lf-num_header-1,1);
                case 'int8'
                    A = repmat(int8(Ar),num_lf-num_header-1,1);
                case 'int16'
                    A = repmat(int16(Ar),num_lf-num_header-1,1);
                case 'int32'
                    A = repmat(int32(Ar),num_lf-num_header-1,1);
                case 'int64'
                    A = repmat(int64(Ar),num_lf-num_header-1,1);
                case 'uint8'
                    A = repmat(uint8(Ar),num_lf-num_header-1,1);
                case 'uint16'
                    A = repmat(uint16(Ar),num_lf-num_header-1,1);
                case 'uint32'
                    A = repmat(uint32(Ar),num_lf-num_header-1,1);
                case 'uint64'
                    A = repmat(uint64(Ar),num_lf-num_header-1,1);
            end
            clear Ar            
        end
        ldx_lo = num_header+1;  % lower row index
        val_cntr = 0;           % number of values read
        char_cntr = 0;          % number of characters read
        diag_cntr = 0;          % loop counter
        while ldx_lo < num_lf
            ldx_hi = min(ldx_lo - 1 + ldx_rng,num_lf);    % lower row index of current working section
            [Atmp,count,errmsg,nextindex] = sscanf(f8( lf_idc(ldx_lo)+1:lf_idc(ldx_hi)),conv_str);    % THE conversion
            char_cntr = char_cntr + nextindex - 1;      
            diag_cntr = diag_cntr + 1;                  
            num_lines_loop = ldx_hi-ldx_lo;
            val_cntr = val_cntr + count;
           
            % error 1) current section was not completely read in
            if ~isempty(errmsg)
                if nextindex <= lf_idc(ldx_hi)-(lf_idc(ldx_lo)+1)+1  
                    % find line break index of the abortion line
                    err_line_idx = min(find(lf_idc-(char_cntr+lf_idc(num_header+1))>0));    %#ok<MXFND>
                    % give user the location of the error cause
                    if infolvl >= 2
                        disp(['Sscanf error after reading ' num2str(val_cntr) ' numeric values. Critical row (no. ' num2str(err_line_idx-1) '): '])
                        disp(f8(lf_idc(err_line_idx-1)+1:lf_idc(err_line_idx)-1)')
                    end % if
                end % if
                break;
            end

            % error 2) number of numeric values is not a multiple of the number of columns
            % try to provide some hints:
            if numel(Atmp) ~= num_colon * num_lines_loop
                dlf = diff(lf_idc(ldx_lo:ldx_hi));      % length of each row
                [dlf_sort,dlf_sort_idc] = sort(dlf);
                % We don't know the lines containing the wrong number of
                % values. As a guess, just show the positions of the
                % longest and the shortest rows (simply count characters).
                if infolvl >= 2
                    disp('Warning: number of values is not a multiple of the number of rows.')
                    disp(['Longest  rows: ' num2str( num_header-1+ldx_lo+dlf_sort_idc(end:-1:end-4)', ' %i' ) ' (' num2str( dlf_sort(end:-1:end-4)', ' %i' ) ' characters) '])
                    disp(['Shortest rows: ' num2str( num_header-1+ldx_lo+dlf_sort_idc(1:5)'         , ' %i' ) ' (' num2str( dlf_sort(1:5)'         , ' %i' ) ' characters) '])
                end % if
                error('Number of values is not a multiple of number of rows.')
            end % if

            % put the values to the right dimensions and add them to A
            Atmp = reshape(Atmp,num_colon,num_lines_loop)';
            A(ldx_lo-num_header:ldx_hi-num_header-1,:) = Atmp;

            ldx_lo = ldx_hi;         % start index for the following loop
            if infolvl >= 1
                waitbar(0.5+0.5*(ldx_lo/num_lf),hw)
            end
        end % while

    catch   %#ok<CTCH> % catch further errors (old catch style)
        if ~exist('errmsg','var') || isempty(errmsg)
            errmsg = lasterr; %#ok<LERR> (old catch style)
        end
    end % try
end

% Quit on error if 'matrix'-mode was enforced:
if strcmpi(readmode,'matrix') && ~isempty(errmsg)
    if infolvl >= 1
        close(hw)
    end
    error(errmsg);
end


%% Converting line-by-line (ReadMode 'Line')

clear Atmp

if strcmpi(readmode,'line') || ~isempty(errmsg)
    num_data_per_row = zeros(num_lf-num_header-1,1);

    if infolvl >= 2 && ~strcmpi(readmode,'line')
        disp('Due to error')
        disp(strrep(['  ' errmsg],char(10),char([10 32 32])))
        disp('txt2mat will now try to read line by line...')
    end % if

    % initialize result matrix A depending on matlab version:
    width_A = max(abs(num_colon),1);
    if vn>=7
        A = NaN*zeros(num_lf-num_header-1,width_A,numerictype);
    else
        % create a single row of A to be repeated if numerictype is other
        % than double:
        Ar= NaN*zeros(1,width_A);
        switch lower(numerictype)
            case 'double'
                A = NaN*zeros(num_lf-num_header-1,width_A);
            case 'single'
                A = repmat(single(Ar),num_lf-num_header-1,1);
            case 'int8'
                A = repmat(int8(Ar),num_lf-num_header-1,1);
            case 'int16'
                A = repmat(int16(Ar),num_lf-num_header-1,1);
            case 'int32'
                A = repmat(int32(Ar),num_lf-num_header-1,1);
            case 'int64'
                A = repmat(int64(Ar),num_lf-num_header-1,1);
            case 'uint8'
                A = repmat(uint8(Ar),num_lf-num_header-1,1);
            case 'uint16'
                A = repmat(uint16(Ar),num_lf-num_header-1,1);
            case 'uint32'
                A = repmat(uint32(Ar),num_lf-num_header-1,1);
            case 'uint64'
                A = repmat(uint64(Ar),num_lf-num_header-1,1);
        end
        clear Ar            
    end
    A1 = A(1);
   
    if infolvl >= 1
        if strcmpi(readmode,'line')
            waitbar(0.5,hw,{'reading line-by-line ...'})
        else
            poshw = get(hw,'Position');
            set(hw,'Position',[poshw(1), poshw(2)-4/7*poshw(4), poshw(3), 11/7*poshw(4)]);
            waitbar(0.5,hw,{'reading line-by-line because of error:';['[' errmsg ']']})
        end
        drawnow
    end
   
   % extract numeric values line-by-line:
   for ldx = num_header+1:(num_lf-1)
        a = sscanf(f8( (lf_idc(ldx)+1) : lf_idc(ldx+1)-1 ),conv_str)';
        num_data_per_row(ldx-num_header) = numel(a);
        % If necessary, expand A along second dimension (allowed by
        % num_colon < 0)
        if (num_data_per_row(ldx-num_header) > width_A) && (num_colon < 0)
            A = [A, repmat(A1,size(A,1),...
                 num_data_per_row(ldx-num_header)-width_A)]; %#ok<AGROW>
            width_A = num_data_per_row(ldx-num_header);
        end
        A(ldx-num_header,1:min(num_data_per_row(ldx-num_header),width_A)) = a(1:min(num_data_per_row(ldx-num_header),width_A));
       
        % display waitbar:
        if ~mod(ldx,10000)
            if infolvl >= 1
                waitbar(0.5+0.5*(ldx./(num_lf-1)),hw)
            end
        end % if
   end % for
   
    % display info about number of numeric values per line
    if infolvl >= 2
        if num_colon>=0
            reference = num_colon;
        elseif num_colon == -1;
            reference = width_A;
        else
            reference = -num_colon;
        end
       
        disp('Row length info:')
        idc_less_data = find(num_data_per_row<reference)+num_header;
        idc_more_data = find(num_data_per_row>reference)+num_header;
        num_less_data = numel(idc_less_data);
        num_more_data = numel(idc_more_data);
        num_equal_data = num_lf-num_header-1 - num_less_data - num_more_data;
        info_ca(1:3,1) = {['  ' num2str(num_equal_data)];['  ' num2str(num_less_data)];['  ' num2str(num_more_data)]};
        info_ca(1:3,2) = {[' row(s) found with ' num2str(reference) ' values'],...
                           ' row(s) found with less values',...
                           ' row(s) found with more values'};
        info_ca(1:3,3) = {' ';' ';' '};
        if num_less_data>0
            info_ca{2,3} = [' (row no. ', num2str(idc_less_data(1:min(10,num_less_data))'), repmat(' ...',1,num_less_data>10), ')'];
        end
        if num_more_data>0
            info_ca{3,3} = [' (row no. ', num2str(idc_more_data(1:min(10,num_more_data))'), repmat(' ...',1,num_more_data>10), ')'];
        end
        disp(strcatcell(info_ca));

    end % if infolvl >= 2
   
end % if

if infolvl >= 1
    close(hw)
end


%% : : : : : subfunction ANATXT : : : : :
function [ffn, nh, nc, cstr, SR, RM, llta, hl, ferrmsg] = anatxt(ffn,fpos,sr_input_ca,replace_expr,replace_regex,kl_input,nh)

% ANATXT analyse data layout in a text file for txt2mat
%
% Usage:
% [ffn, nh, nc, cstr, SR, RM, llta, hl, ferrmsg] = ...
%       anatxt(fn,fpos,sr_input_ca,replace_expr,replace_regex,nh);
%
% ffn           full file name of analysed file
% nh            number of header lines
% nc            number of columns
% cstr          conversion string (curr. always '%f')
% SR            character replacement string
% RM            recommended read mode
% llta          lines analysed after header
% hl            header line characters
% ferrmsg       file operation error message
%
% fn            file name
% fpos          file position to start reading at
% sr_input      character replacement argument as for txt2mat
% replace_expr  expression replacement argument as for txt2mat
% replace_regex regular expression replacement argument as for txt2mat
% kl_input      cell array of strings to skip lines
% nh            number of header lines; NaN if not provided

%   Copyright 2006 A.Tönnesmann, The PierWorks, Inc.
%   $Revision: 2.80 $  $Date: 2008/04/05 13:05:08 $

% v = ver('matlab');
% vn= str2double(v.Version);

num_rr       = length(replace_regex);
num_er       = length(replace_expr);
num_sr       = length(sr_input_ca);

%% Read in file

% definitions
num_chars_read = 65536; % number of characters to read
has_nuff_n_ratio = 0.1; % this ratio will tell if a row has enough values
cstr     = '%f';        % assume floats only (so far)

has_ferror = false; % init
ferrmsg = '';       % init

logfid = fopen(ffn);
if fpos > 0
    status = fseek(logfid,fpos,'bof');
    if status ~= 0
        has_ferror = true;
        ferrmsg = ferror(logfid,'clear');
    end
end

if ~has_ferror
    [f8,f8cnt] = fread(logfid,num_chars_read,'*uint8'); % THE read
    if f8cnt < num_chars_read
        did_read_to_end = true;
    else
        did_read_to_end = false;
    end
    f8 = f8';
end
fclose(logfid);


if has_ferror || isempty(f8)
    [nh, nc, cstr, llta] = deal(0);
    [cstr, SR, RM, hl]   = deal('');
    return
end


%% Replace regular expressions, expressions and characters, if needed
       
if num_er>0 || num_sr>0 || num_rr>0
    f8=char(f8);
   
    if num_rr>0
        for vdx = 1:num_rr                  % step through replacement arguments
            srarg = replace_regex{vdx};       % pick a single argument
            for sdx = 1:(numel(srarg)-1)
                f8 = regexprep(f8, srarg{sdx}, srarg{end});
            end
        end
    end

    if num_er>0
        for vdx = 1:num_er                  % step through replacement arguments
            srarg = replace_expr{vdx};       % pick a single argument
            for sdx = 1:(numel(srarg)-1)
                f8 = strrep(f8, srarg{sdx}, srarg{end});
            end
        end
    end

    if num_sr>0
        for vdx = 1:num_sr                  % step through replacement arguments
            srarg = sr_input_ca{vdx};       % pick a single argument
            for sdx = 1:(numel(srarg)-1)
                rep_idx = strfind(f8,srarg(sdx));
                f8(rep_idx) = srarg(end);   % perform replacement
            end
        end
    end
   
    f8 = uint8(f8);
end


%% Find linebreaks

% Detect line termination character
lbfull = detect_line_break_characters(ffn);
lbuint = lbfull(end);          
%lbstr  = char(lbfull);

% if we are sure we read the whole file, add a final linebreak:
if did_read_to_end
    f8 = [f8,lbfull];
end

% preliminary linebreak positions:
idc_lb = find(f8==lbuint);

% position of the endmost printable ASCII character in f8
% (switch to uint8 and use V6.X find arguments for compatibility)
printasc = uint8([32:127, 128+32:255]);             % printable ASCIIs
idx_last_pa = max(find(ismembc(double(f8),double(printasc))));  %#ok<MXFND> % new syntax: find(ismembc(f8,dec_nr), 1, 'last' )
                                                       
% trim f8 after the first linebreak after this character, or, if none
% present, after the first linebreak before it:
if any(idc_lb>idx_last_pa)
    f8 = f8(1:min(idc_lb(idc_lb>idx_last_pa)));
else
    f8 = f8(1:max(idc_lb));
end
   
% recover linebreak positions
is_lb   = f8==lbuint;
idc_lb  = find(is_lb);

    %% Find bad line positions
    num_kl = numel(kl_input);
    % Check for possible bad line markers
    kl_idc = [];
    if num_kl>0
       
        for idx = 1:num_kl                      % find positions of all markers
            kl_idx_akt = strfind(char(f8),kl_input{idx})';
            kl_idc = [kl_idc; kl_idx_akt]; %#ok<AGROW>
        end % for
    end

    %% Delete rows marked as bad if we found bad line markers
    if ~isempty(kl_idc)

        % find indices of line breaks bordering a marker
        [L,R] = neighbours(kl_idc, idc_lb);
        % care for multiple markers within a single row
        if any(diff(L) <= 0) && any(diff(R) <= 0)
            L = unique(L);
            R = unique(R);
        end
        % delete the bad rows
        f8 = cutvec(f8,L+1,R,false);

        % update line break indices
        is_lb   = f8==lbuint;
        idc_lb  = find(is_lb);
    end

num_lb  = numel(idc_lb);

f8c = char(f8);
f8d = double(f8);

%% Find character types

% types of characters:
dec_nr_p = sort(uint8('+-1234567890eE.NanIiFf'));   % decimals with NaN, Inf, signs and .
sep_wo_k = uint8([9 32    47 58 59]);      % separators excluding comma  
sep_wi_k = uint8([9 32 44 47 58 59]);      % separators including comma (Tab Space ,/:Wink
komma    = uint8(',');                  % ,
other    = setdiff(printasc, [sep_wi_k, dec_nr_p]); % printables without separators and decimals

% characters not expected to appear in the data lines:
is_othr = ismembc(f8d,double(other));       % switch to double for compatibility
is_beg_othr = diff([false, is_othr]);       % true where groups of such characters begin
idc_beg_othr = find(is_beg_othr==1);        % start indices of these groups
[S, sidx] = sort([idc_lb,idc_beg_othr]);    % in sidx, the numbers (1:num_lb) representing the linebreaks are placed between the indices of the start indices from above
num_beg_othr_per_line = diff([0,find(sidx<=num_lb)]) - 1;   % number of character groups per line

% numbers enclosing a dot:
% idc_digdotdig = regexp(f8c, '[\+\-]?\d+\.\d+([eE][\+\-]?\d+)?', 'start');
idc_digdotdig = regexp(f8c, '[\+\-]?\d+\.\d+([eE][\+\-]?\d+)?');
[S, sidx] = sort([idc_lb,idc_digdotdig]);
num_beg_digdotdig_per_line = diff([0,find(sidx<=num_lb)]) - 1;

% numbers enclosing a comma:
% idc_digkomdig = regexp(f8c, '[\+\-]?\d+,\d+([eE][\+\-]?\d+)?', 'start');
idc_digkomdig = regexp(f8c, '[\+\-]?\d+,\d+([eE][\+\-]?\d+)?');
[S, sidx] = sort([idc_lb,idc_digkomdig]);
num_beg_digkomdig_per_line = diff([0,find(sidx<=num_lb)]) - 1;

% numbers without a dot or a comma:
% idc_numbers = regexp(f8c, '[\+\-]?\d+([eE][\+\-]?\d+)?', 'start');
idc_numbers = regexp(f8c, '[\+\-]?\d+([eE][\+\-]?\d+)?');
[S, sidx] = sort([idc_lb,idc_numbers]);
num_beg_numbers_per_line = diff([0,find(sidx<=num_lb)]) - 1;

% NaN and Inf items :
idc_nan = regexpi(f8c, '\<[\+\-]?(nan|inf)\>');
[S, sidx] = sort([idc_lb,idc_nan]);
num_beg_nan_per_line = diff([0,find(sidx<=num_lb)]) - 1;

% commas enclosed by numeric digits
% idc_kombd = regexp(f8c, '(?<=[\d]),(?=[\d])', 'start');
% if vn>=7
%     idc_kombd = regexp(f8c, '(?<=[\d]),(?=[\d])');  % lookaround new to v7.0??
% else
    idc_kombd = 1+regexp(f8c, '\d,\d');
% end
[S, sidx] = sort([idc_lb,idc_kombd]);
num_beg_kombd_per_line = diff([0,find(sidx<=num_lb)]) - 1;

% two sequential commas without a (different) separator inbetween
% idc_2kom  = regexp(f8c, ',[^\s:;],', 'start');
idc_2kom  = regexp(f8c, ',[^\s:;/],');

% commas:
is_kom  = f8==komma;
idc_kom = find(is_kom);
[S, sidx] = sort([idc_lb,idc_kom]);
num_kom_per_line = diff([0,find(sidx<=num_lb)]) - 1;


%% Analyse

if isnan(nh)
    % Determine number of header lines:
    nh = max([0, find(num_beg_othr_per_line>0)]); %#ok<MXFND>     % for now, take the last line containing an 'other'-character
    num_beg_numbers_ph = num_beg_numbers_per_line(nh+1:end)+num_beg_nan_per_line(nh+1:end);    % number of lines following
    % by definition, a line is a valid data line if it contains enough numbers
    % compared to the average:
    has_enough_numbers = num_beg_numbers_ph>has_nuff_n_ratio.*mean(num_beg_numbers_ph);  
    nh = nh + min(find(has_enough_numbers)) - 1; %#ok<MXFND>
end
   

if nh>0
    f8v_idx1 = idc_lb(nh)+1;
    hl = char(f8(1:idc_lb(nh)));
else
    f8v_idx1 = 1;
    hl = [];
end

f8v = f8(f8v_idx1:end); % valid data section of f8
llta = num_lb - nh;     % number of non-header lines to analyse
% todo: handle llta==0


% find out decimal character (. or ,)
SR = {};        % Init. replacement character string
SR_idx = 0;     % Init. counter of the above
sepchar = '';   % Init. separator (delimiter) character
decchar = '.';  % Init. decimal character (default)

num_values_per_line = -num_beg_digdotdig_per_line + num_beg_numbers_per_line;

% Are there commas? If yes, are they decimal commas or delimiters?
if any( num_kom_per_line(nh+1:end) > 0 )
    sepchar = ',';  % preliminary take comma for delimiter
    % Decimal commas are neighboured by two numeric digits ...
    % and between two commas there has to be another separator
    if  all(num_kom_per_line(nh+1:end) == num_beg_kombd_per_line(nh+1:end)) ... % Are all commas enclosed by numeric digits?
        && ~any(num_beg_digdotdig_per_line(nh+1:end) > 0) ...   % There are no numbers with dots?
        && ~any(idc_2kom(nh+1:end) > 0)                         % There is no pair of commas with no other separator inbetween?

        decchar = ',';
        sepchar = '';
       
        num_values_per_line = -num_beg_digkomdig_per_line + num_beg_numbers_per_line; % number of values per line
    end
end

% replacement string for replacements by spaces
% other separators
is_wo_k_found = ismember(sep_wo_k, f8v);  % Tab Space : ;
is_other_found= ismember(other,f8v);      % other printable ASCIIs

% possible replacement string to replace : and ;
sr1 = [sepchar, char(sep_wo_k([0 0 1 1 1]&is_wo_k_found))];  
% possible replacement string to replace other characters
sr2 = char(other(is_other_found));        % still obsolete as such lines are treated as header lines

if numel([sr1,sr2])>0
    SR_idx = SR_idx + 1;
    SR{SR_idx} = [sr1, sr2, ' '];
end

% possible replacement string to replace the decimal character
if strcmp(decchar,',')
    SR_idx = SR_idx + 1;
    SR{SR_idx} = ',.';
end

num_items_per_line = num_values_per_line + num_beg_nan_per_line;

nc = max(num_items_per_line(nh+1:end));    % proposed number of columns

% suggest a proper read mode depending on uniformity of the number of values per
% line
if numel(unique(num_items_per_line(nh+1:end))) > 1
    RM = 'line';
else
    RM = 'auto';
end

%% : : : : : further subfunctions : : : : :

function s = strcatcell(C)

% STRCATCELL Concatenate strings of a 1D/2D cell array of strings
%
% C = {'a ','123';'b','12'}
%   C =
%     'a '    '123'
%     'b'     '12'
% s = strcatcell(C)
%   s =
%     a 123
%     b 12

num_col = size(C,2);
D = cell(1,num_col);
for idx = 1:num_col
    D{idx} = char(C{:,idx});
end
s = [D{:}];

function [L,R] = neighbours(a,b)

% NEIGHBOURS find nearest neighbours in a given set of values
%
% [L,R] = neighbours(a,b)
%
% find neighbours of elements of a in b:
% L(i): b(i) with a(i)-b minimal, a(i)-b >0 (left neighbour)
% R(i): b(i) with b-a(i) minimal, b-a(i)>=0 (right neighbour)
%
% If no left or right neighbour matching the above criteria can be found
% in b, -Inf or Inf (respectively) will be returned.
%
%
% EXAMPLE:
% [L,R] = neighbours([-5, pi, 101],[-5:2:101])
%
% L =
%   -Inf
%      3
%     99
% R =
%     -5
%      5
%    101

len_a = length(a);
ab    = [a(:);-Inf;b(:);Inf];

[ab,ix] = sort(ab);
[ix,jx] = sort(ix);

L = ab(max(1,jx(1:len_a)-1));
R = ab(jx(1:len_a)+1);

% todo: check if there's a better solution with histc

function [w, newidcoi, do_keep] = cutvec(v,li,hi,keep_flag,varargin)

% CUTVEC cut out multiple sections from a vector by index ranges
%
% USAGE:
%   w = cutvec(v,li,hi,keep_flag)
% OR
%   [w, new_idc_oi, do_keep] = cutvec(v,li,hi,keep_flag,old_idc_oi)
%
% v             input vector
% w             output vector consisting of v-sections
% li            lower limits of ranges (sorted!)
% hi            upper limits of ranges (sorted!)
% keep_flag     true:   cut out values outside the ranges
%               false:  cut out values within the ranges
% old_idc_oi    indices of interest in v
% new_idc_oi    corresponding indices of interest in w
% do_keep       logical matrix with w=v(do_keep)
%
% EXAMPLE:
%
% w = cutvec([1:20],[3,10,16],[7,12,19],1)
%
%   =>  w = [3 4 5 6 7   10 11 12   16 17 18 19]
%
% w = cutvec([1:20]*2,[3,10,16],[7,12,19],0)
%
%   =>  w = [2 4    16 18    26 28 30    40]
%
% tic, w = cutvec([1:5000000]',[100:500:5000000],[200:500:5000000],0); toc
%
% elapsed_time =
%
%     0.4380
% v = 1:20;
% li= [10,18];
% hi= [12,19];
% keep_flag = 0;
% idcoi = [1,4,7,10,13,18,20];
%
% [w, newidcoi, do_keep] = cutvec(v,li,hi,keep_flag,idcoi)

%   $Revision: 1.10 $

len_v   = length(v);
len_i   = length(li);
k_flag  = logical(keep_flag);
has_idcoi = false;
newidcoi=[];

if nargin == 5
    idcoi   = int32(varargin{1});
    if ~issorted(idcoi)
        error([mfilename ':vector of indices of interest must be sorted!'])
    end
    has_idcoi = true;
end

% init:
if k_flag
    do_keep = false(len_v,1);
else
    do_keep = true(len_v,1);
end

for i = 1:len_i
    do_keep(li(i):hi(i)) = k_flag;
end
% How to do it without a loop??

if has_idcoi
    remidc   = int32(find(do_keep));
    newidcoi = ismembc2(idcoi,remidc);
end

w = v(do_keep);

function ia = argincheck(allargin)

% ARGCHECK check input arguments for txt2mat
%
% ia = argincheck(allargin)
% provides input argument information in struct ia with fields
%       ia.is_argin_num_header
%       ia.num_header
%       ia.is_argin_num_colon
%       ia.num_colon
%       ...

% Check input argument occurence (Property/Value-pairs)
%  1 'NumHeaderLines',     Scalar,     13
%  2 'NumColumns',         Scalar,     100
%  3 'ConvString',         String,     ['%d.%d.%d' repmat('%f',1,6)]
%  4 'ReplaceChar',        CellAString {')Rx ',';: '}
%  5 'BadLineString'       CellAString {'Warng', 'Bad'}
%  6 'ReplaceExpr',        CellAString {{'True','1'},{'False','0'},{'#Inf','Inf'}}
%  7 'DialogString'        String      'Now choose a Labview-Logfile'
%  8 'MemPar'              2x1-Vector  [2e7, 2e5]
%  9 'InfoLevel'           Scalar      2
% 10 'ReadMode'            String      'Auto'
% 11 'NumericType'         String      'single'
% 12 'RowRange'            2x1-Vector  [1,Inf]
% 13 'FilePos'             Scalar      1e5
% 14 'ReplaceRegExpr'      CellArOfStr {{'True','1'},{'False','0'},{'#Inf','Inf'}}

propnames   = {'NumHeaderLines','NumColumns','ConvString','ReplaceChar',...
               'BadLineString','ReplaceExpr','DialogString','MemPar',...
               'InfoLevel','ReadMode','NumericType','RowRange',...
               'FilePos','ReplaceRegExpr'};
len_pn      = length(propnames);
proppos     = zeros(size(propnames));   % argument-no. Property-String
valpos      = zeros(size(propnames));   % argument-no. Value

% compare the possible property strings to all arguments and save what
% can be found at which argument number to <proppos> and <valpos>
for adx = 2:length(allargin) %nargin    % look at all args but the first
    if ischar(allargin{adx})            % if it is a string...
        for pdx = 1:len_pn
            if isequal(lower(propnames{pdx}),lower(allargin{adx}))
                if proppos(pdx) ~= 0
                   error(['Multiple occurence of ' propnames{pdx} ' argument.'])
                end
                proppos(pdx) = adx;
                valpos(pdx)  = adx+1;
            end
        end
    end
end

% add argument numbers that have no property string, i.e. that occur
% before the first property string
firstproppos = min(proppos(proppos>0));
if isempty(firstproppos)
    for pdx = 2:length(allargin)
        valpos(pdx-1) = pdx;
    end % for
else
    for pdx = 2:firstproppos-1
        if proppos(pdx-1) ~= 0
            error(['Multiple occurence of ' propnames{pdx-1} ' argument.'])
        end
        valpos(pdx-1) = pdx;
    end
end


% Check input argument contents
% todo: complete type checking
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
is_argin_num_header= false; % Init., is an argument for the number of header lines given?
if valpos(1) ~= 0
    num_header  = allargin{valpos(1)};
    if ~isempty(num_header)
        is_argin_num_header = true;
    end
else
    num_header = NaN;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
is_argin_num_colon = false; % Init., is an argument for the number of data columns lines given?
if valpos(2) ~= 0
    num_colon   = allargin{valpos(2)};
    if ~isempty(num_colon)
        is_argin_num_colon = true;
    end
else
    num_colon = [];
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%is_argin_conv_str  = false; % Init., conversion string argument given?
if valpos(3) ~= 0
    conv_str    = allargin{valpos(3)};
    if isempty(conv_str)
        conv_str = '%f';
    %else
    %    is_argin_conv_str = true;
    end
else
    %conv_str = {};
    conv_str = '%f';    % standard, as always returned by anatxt
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Check for character replacement argument. For compatibility reasons,
% multiple strings as separate arguments are still supported.
has_sr_input_only = false;
sr_input_ca = {};
if valpos(4) ~= 0
    if iscellstr(allargin{valpos(4)})
        sr_input_ca = allargin{valpos(4)};
    elseif ischar(allargin{valpos(4)});
        sr_input_ca = {allargin{valpos(4):end}};
        disp([mfilename ': for future versions, please use a single cell array of strings as an input argument for multiple replacement strings.'])
        has_sr_input_only = true;
    else
        error('replacement string argument must be of type string or cell array of strings')
    end
    num_sr      = length(sr_input_ca);
else
    num_sr      = 0;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(5) ~= 0 && ~has_sr_input_only     % bad line strings
    if iscellstr(allargin{valpos(5)})
        kl_input_ca = allargin{valpos(5)};      
    elseif ischar(allargin{valpos(5)});
        kl_input_ca = {allargin{valpos(5)}};
        disp([mfilename ': for future versions, please use a single cell array of strings as an input argument for bad line marker strings.'])
    else
        error('bad line marker argument must be of type string or cell array of strings')
    end
    num_kl      = length(kl_input_ca);
else
    num_kl      = 0;
    kl_input_ca = {};
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(6) ~= 0   % 'ReplaceExpression'
    replace_expr = allargin{valpos(6)};
    num_er       = length(replace_expr);
else
    replace_expr = {};
    num_er       = 0;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(7) ~= 0           % 'DialogString'
    dialog_string = allargin{valpos(7)};
else
    dialog_string = 'Choose a data file';
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(8) ~= 0           % 'MemPar'
    mem_par  = allargin{valpos(8)};
    idx_rng  = mem_par(1);
    ldx_rng  = mem_par(2);
else
    idx_rng  = 2E7; % idx_rng  = 2E7; % number of characters to be processed simultaneously (memory-dependent!)
    ldx_rng  = 2E5; % ldx_rng  = 2E5; % number of rows to be processed simultaneously (memory-dependent!)
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(9) ~= 0           % 'InfoLevel'
    infolvl  = allargin{valpos(9)};
else
    infolvl  = 2;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(10) ~= 0          % 'ReadMode'
    readmode = allargin{valpos(10)};
    is_argin_readmode = true;
    %% force readmode to 'line' if num_colon < 0
    if is_argin_num_colon && num_colon < 0 && ~strcmpi(readmode,'line');
        readmode = 'line';
        warning('txt2mat:ineptReadmode', ...
            'ReadMode is set to ''line'' as NumColumns was given as negative.')
    end
else
    is_argin_readmode = false;
    if is_argin_num_colon && num_colon < 0;
        readmode = 'line';
    else
        readmode = 'auto';
    end
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(11) ~= 0          % 'NumericType'
    numerictype = allargin{valpos(11)};
else
    numerictype = 'double';
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(12) ~= 0          % 'RowRange'
    rowrange = allargin{valpos(12)};
    if ~(numel(rowrange)==2) || ~issorted(rowrange) || rowrange(1)<1 || ...
        (rem(rowrange(1),1)~=0) || ( (rem(rowrange(2),1)~=0) && (rowrange(2)~=Inf) )
        error('RowRange argument must be a sorted positive integer 2x1 vector.')
    end
    is_argin_rowrange = true;
else
    is_argin_rowrange = false;  
    rowrange = [1,Inf];
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(13) ~= 0          % 'FilePos'
    filepos = allargin{valpos(13)};
    if filepos<0 || (rem(filepos,1)~=0)
        error('FilePos argument must be a nonnegative integer.')
    end
    is_argin_filepos = true;
else
    is_argin_filepos = false;
    filepos = 0;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if valpos(14) ~= 0   % 'ReplaceRegExpr'
    replace_regex= allargin{valpos(14)};
    num_rr       = length(replace_regex);
else
    replace_regex= {};
    num_rr       = 0;
end
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% handle file name argument
if nargin == 0 || isempty(allargin{1})  % no file or path name given?
    [filn,pn] = uigetfile('*.*', dialog_string);    % open file dialogue
    ffn = fullfile(pn,filn);
elseif exist(allargin{1},'dir') == 7    % only path name given
    curcd = cd;
    cd(allargin{1});                    % temporarily change directory
    [filn,pn] = uigetfile('*.*', dialog_string);    % open file dialogue
    ffn = fullfile(pn,filn);
    cd(curcd);
elseif exist(allargin{1},'file')        % file name given
    ffn  = allargin{1};
   [dum_pathstr,name,ext] = fileparts(ffn);
   filn = [name,ext];
else                                    % wrong name
    error([mfilename ': no such file or directory.'])
end
if exist(ffn,'file')~=2                 % check again (e.g. afger ESC in open file dialogue)
    error('No existing file given.')
end

% generate a shortened form of the file name:
if length(filn) < 28
    ffn_short = filn;
else
    ffn_short = ['...' filn(end-17:end)];
end

ia.is_argin_num_header    = is_argin_num_header;
ia.num_header             = num_header;
ia.is_argin_num_colon     = is_argin_num_colon;
ia.num_colon             = num_colon;
ia.conv_str              = conv_str;
ia.sr_input_ca           = sr_input_ca;
ia.num_sr                 = num_sr;
ia.kl_input_ca           = kl_input_ca;
ia.num_kl               = num_kl;
ia.replace_expr         = replace_expr;
ia.num_er               = num_er;
ia.idx_rng              = idx_rng;
ia.ldx_rng              = ldx_rng;
ia.infolvl              = infolvl;
ia.is_argin_readmode    = is_argin_readmode;
ia.readmode             = readmode;
ia.numerictype          = numerictype;
ia.is_argin_rowrange    = is_argin_rowrange;
ia.rowrange             = rowrange;
ia.filepos              = filepos;
ia.is_argin_filepos     = is_argin_filepos;
ia.replace_regex        = replace_regex;
ia.num_rr               = num_rr;
ia.ffn                  = ffn;
ia.ffn_short            = ffn_short;

function lb = detect_line_break_characters(ffn)

% DETECT_LINE_BREAK_CHARACTERS find out type of line termination of a file
%
% lb = detect_line_break_characters(ffn)
%
% with
%   ffn     ascii file name
%   lb      line break character(s) as uint8, i.e.
%           [13 10]     (cr+lf) for standard DOS / Windows files
%           [10]        (lf) for Unix files
%           [13]        (cr) for Mac files
%
% The DOS style values are returned as defaults if no such line breaks are
% found.



lfuint   = uint8(10);   % LineFeed
cruint   = uint8(13);   % CarriageReturn
crlfuint = [cruint,lfuint];
lfchar   = char(10);
crchar   = char(13);
crlfchar = [crchar,lfchar];
readlen  = 16384;

% Cycle through file and read until we find line termination characters or
% we reach the end of file.
% Possible line breaks are: cr+lf (default), lf, cr

logfid = fopen(ffn);
has_found_lbs = false;
while ~has_found_lbs

    [f8,cntr] = fread(logfid,readlen,'*char');

    pos_crlf = strfind(f8',crlfchar);
    pos_lf   = strfind(f8',lfchar);
    pos_cr   = strfind(f8(1:end-1)',crchar);
    % here we ignored a cr at the end as it might belong to a cr+lf
    % combination (later we'll step back one byte in the file position to
    % avoid overlooking such a single cr)

    num_lbs = [numel(pos_crlf),numel(pos_lf),numel(pos_cr)];

    if all(num_lbs==0)
        fseek(logfid, -1, 0);    % step back one byte
       
        % if we reached the end of file without finding any special
        % character, set the endmost line break character and the complete
        % line break character to DOS values as defaults
        if cntr < readlen
            has_found_lbs = true;   % just to exit the while loop
            lb = crlfuint;          % complete line break character set
        end
    elseif num_lbs(1)>0
        has_found_lbs = true;
        lb = crlfuint;
    elseif num_lbs(2)>0
        has_found_lbs = true;
        lb = lfuint;
    elseif num_lbs(3)>0
        has_found_lbs = true;
        lb = cruint;
    end
end
fclose(logfid);
 
Private Nachricht senden Benutzer-Profile anzeigen
 
n.force
Forum-Century

Forum-Century


Beiträge: 118
Anmeldedatum: 02.03.12
Wohnort: nähe Magdeburg
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:09     Titel:
  Antworten mit Zitat      
Könntest du mal eine *.pts Datei mit anfügen???
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:18     Titel:
  Antworten mit Zitat      
hatte den datei namen nun geändert weil er es sonst nicht angehangen hat

test.txt
 Beschreibung:
pts

Download
 Dateiname:  test.txt
 Dateigröße:  9.89 MB
 Heruntergeladen:  421 mal
Private Nachricht senden Benutzer-Profile anzeigen
 
n.force
Forum-Century

Forum-Century


Beiträge: 118
Anmeldedatum: 02.03.12
Wohnort: nähe Magdeburg
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:41     Titel:
  Antworten mit Zitat      
Ich habe leider keine Ahnung, was das Problem ist. Die ganzen Scripts sind auch sehr umfangreich. Ich denke, dass es was mit der

Code:
txt2mat_01


Funktion zu tun hat. Vielleicht wurde sie nicht richtig definiert o.ä.

Frag am besten deinen Kollegen. Schliesslich hat er das Programm geschrieben...

Viel Erfolg
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:51     Titel:
  Antworten mit Zitat      
die txt2mat_01 hat er nicht selber geschrieben glaub ich die hat er aus dem internet. Doof ist das er selten da ist. Evil or Very Mad
Private Nachricht senden Benutzer-Profile anzeigen
 
n.force
Forum-Century

Forum-Century


Beiträge: 118
Anmeldedatum: 02.03.12
Wohnort: nähe Magdeburg
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:52     Titel:
  Antworten mit Zitat      
Hat es denn bei ihm jemals funktioniert???
Private Nachricht senden Benutzer-Profile anzeigen
 
qwertz123
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 16
Anmeldedatum: 22.12.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 05.03.2012, 12:58     Titel:
  Antworten mit Zitat      
geh ich von aus sonst hätte er es mir ja nicht gegeben

wenn ich eine datei lade und diese dann mit txt2mat auswerte klappt das auch. Nur wenn ich das üer die plotprofil mache funzt es nicht
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.