I dont know why my code does not work... Can anybody help me?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Philipp Mueller
el 16 de Nov. de 2016
Comentada: Philipp Mueller
el 21 de Nov. de 2016
I want to read my 'Rainflow_Data_Limits_Settings.txt' file in matlab. Everything works except: diagramlimits
My diagramlimits2 diagramlimits3 have the same values -> Why? Thank you for your help. Here is my code:
clear all %löscht alle Variablen
clear clc %löscht den Bildschirm
%Gliederungen
diagramoptions = [];
diagramlimits = [];
inputdata = [];
diagramoptions2 = [];
diagramlimits2 = [];
inputdata2 = [];
diagramoptions3 = [];
diagramlimits3 = [];
inputdata3 = [];
%liest mein Textfile ein.
wholecontent = fileread('Rainflow_Data_Limits_Settings.txt')
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
for section = sections
switch(strtrim(section{1}{1}))%newTxt = strtrim(txt) entfernt führende und nachfolgende Leerzeichen Zeichen von txt und gibt das Ergebnis als newTxtzurück. strtrim wird jedoch nicht signifikanten Leerzeichen entfernt. Zum Beispiel strtrim entfernt führende und nachfolgende Leerzeichen und Tabulatorzeichen, aber beseitigt nicht das geschützte Leerzeichen, char(160).
case 'Diagram Options' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Limits'
header = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content = textscan(section{1}{2}, repmat('%f', 1, numel(header)), 'HeaderLines', 2)
diagramlimits = table(content{:}, 'VariableNames', header)
case 'Input Data'
inputdata = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%dh: ich habe 1 Headerline zur besseren übersicht
case 'Diagram Options2' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues2 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions2 = cell2table(vertcat(keyvalues2{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Limits2'
header2 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content2 = textscan(section{1}{2}, repmat('%f', 1, numel(header2)), 'HeaderLines', 2)
diagramlimits2 = table(content{:}, 'VariableNames', header2)
case 'Input Data2'
inputdata2 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%dh: ich habe 1 Headerline zur besseren übersicht
case 'Diagram Options3' %Diagram Options -> siehe meine Gliederung im .txt file
keyvalues3 = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')%\n -> new line; \r carriage return
diagramoptions3 = cell2table(vertcat(keyvalues3{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Limits3'
header3 = strsplit(regexp(section{1}{2}, '[^\n\r]*', 'match', 'once'))
content3 = textscan(section{1}{2}, repmat('%f', 1, numel(header3)), 'HeaderLines', 2)
diagramlimits3 = table(content{:}, 'VariableNames', header3)
case 'Input Data3'
inputdata3 = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))%dh: ich habe 1 Headerline zur besseren übersicht
otherwise
warning('Unknown section: %s', section{1}{1})
end
end
%öffnet die output fenster
openvar diagramoptions
openvar diagramlimits
openvar inputdata
openvar diagramoptions2
openvar diagramlimits2
openvar inputdata2
openvar diagramoptions3
openvar diagramlimits3
openvar inputdata3
1 comentario
dpb
el 16 de Nov. de 2016
Dunno, but I'd suggest using debugger and set breakpoint on the two sections in question and see what seems to go wrong...you can probably figure out the problem faster than somebody totally unfamiliar with the dataset can..
Respuesta aceptada
Image Analyst
el 16 de Nov. de 2016
diagramlimits2 is using content instead of content2. To fix:
diagramlimits2 = table(content2{:}, 'VariableNames', header2)
same for diagramlimits3:
diagramlimits2 = table(content3{:}, 'VariableNames', header2)
Más respuestas (0)
Ver también
Categorías
Más información sobre Standard File Formats en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!