Filter löschen
Filter löschen

Missing new line after Datapair

2 Ansichten (letzte 30 Tage)
Nainpreet
Nainpreet am 11 Apr. 2023
Kommentiert: Mathieu NOE am 12 Apr. 2023
The output of my Data is messed up, i get the following output
30.0000 22.73685730.2500 22.21240530.5000 22.25532930.7500 22.93022431.0000 22.481385
but i want
30.0000 22.736857
30.2500 22.212405
30.5000 22.255329
30.7500 22.930224
31.0000 22.481385
my code is the following:
%% Import data from text file
% Script for importing data from the following text file:
%
% filename:
% \\Dedosan001\vol1\E\EMV\Kularia\Matlabprogramm\04_Messungen\04\Ergebnistabelle_AV.asc
%
% Auto-generated by MATLAB on 06-Apr-2023 11:22:46
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 9, "Encoding", "UTF16-LE");
% Specify range and delimiter
opts.DataLines = [30, 711];
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["Frequenz", "PK_MAXH", "Var3", "Var4", "Var5", "Var6", "Var7", "Var8", "Var9"];
opts.SelectedVariableNames = ["Frequenz", "PK_MAXH"];
opts.VariableTypes = ["double", "double", "string", "string", "string", "string", "string", "string", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["Var3", "Var4", "Var5", "Var6", "Var7", "Var8", "Var9"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["Var3", "Var4", "Var5", "Var6", "Var7", "Var8", "Var9"], "EmptyFieldRule", "auto");
% Import the data
ErgebnistabelleAV1 = readtable("\\Dedosan001\vol1\E\EMV\Kularia\Matlabprogramm\04_Messungen\04\Ergebnistabelle_AV.asc", opts);
%% Clear temporary variables
clear opts
% Speichern der ersten beiden Spalten in einer neuen Datei
outputFilePath = '\\DEDOSAN001\vol1\E\EMV\Kularia\Matlabprogramm\15\1_2.asc';
fileID = fopen(outputFilePath, 'w');
for i = 1:size(ErgebnistabelleAV1, 1)
% Format für Frequenz ohne wissenschaftliche Schreibweise und mit 3 Dezimalstellen
fprintf(fileID, '%0.4f\t%f\n', ErgebnistabelleAV1.Frequenz(i), ErgebnistabelleAV1.PK_MAXH(i));
fprintf(fileID, '\n'); % Neue Zeile nach jedem Datenpaar
end
fclose(fileID);
  2 Kommentare
Mathieu NOE
Mathieu NOE am 11 Apr. 2023
hello
it would help to have the data file as well (Ergebnistabelle_AV.asc)
Nainpreet
Nainpreet am 11 Apr. 2023
i attached it, but i had to change it to a .txt to upload it

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 12 Apr. 2023
hello again
this is what I believe is what you wanted as output format (table)
T =
681×8 table
Frequenz PK_MAXH AVG_MAXH Hhe Pol Azimut Korr Kommentar
________ _______ ________ ___ _____ ______ ______ _________
30 22.737 9.3353 100 {'H'} -1 12.438 NaN
30.25 22.212 9.2704 100 {'H'} -1 12.436 NaN
30.5 22.255 9.2245 100 {'H'} -1 12.433 NaN
30.75 22.93 9.1978 100 {'H'} -1 12.431 NaN
31 22.481 9.1856 100 {'H'} -1 12.428 NaN
31.25 22.594 9.1831 100 {'H'} -1 12.426 NaN
31.5 22.27 9.1856 100 {'H'} -1 12.423 NaN
31.75 22.992 9.1929 100 {'H'} -1 12.421 NaN
32 22.508 9.2195 100 {'H'} -1 12.418 NaN
Code a bit tweaked (made with import tool) :
T = importfile1('Ergebnistabelle_AV.txt');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ErgebnistabelleAV = importfile1(filename, dataLines)
%IMPORTFILE1 Import data from a text file
% ERGEBNISTABELLEAV = IMPORTFILE1(FILENAME) reads data from text file
% FILENAME for the default selection. Returns the data as a table.
%
% ERGEBNISTABELLEAV = IMPORTFILE1(FILE, DATALINES) reads data for the
% specified row interval(s) of text file FILENAME. Specify DATALINES as
% a positive scalar integer or a N-by-2 array of positive scalar
% integers for dis-contiguous row intervals.
%
% Example:
% ErgebnistabelleAV = importfile1("C:\Users\A0H36019\Documents\Ergebnistabelle_AV.txt", [30, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 12-Apr-2023 11:42:26
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [30, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 8, "Encoding", "UTF16-LE");
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["Frequenz", "PK_MAXH", "AVG_MAXH", "Hhe", "Pol", "Azimut", "Korr", "Kommentar"];
opts.VariableTypes = ["double", "double", "double", "double", "char", "double", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "Hhe", "EmptyFieldRule", "auto");
% Import the data
ErgebnistabelleAV = readtable(filename, opts);
end
  2 Kommentare
Nainpreet
Nainpreet am 12 Apr. 2023
thanks, that worked like a charm
Mathieu NOE
Mathieu NOE am 12 Apr. 2023
My pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by