필터 지우기
필터 지우기

I dont know why my code does not work... Can anybody help me?

조회 수: 2 (최근 30일)
Philipp Mueller
Philipp Mueller 2016년 11월 16일
댓글: Philipp Mueller 2016년 11월 21일
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
dpb
dpb 2016년 11월 16일
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..

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 11월 16일
diagramlimits2 is using content instead of content2. To fix:
diagramlimits2 = table(content2{:}, 'VariableNames', header2)
same for diagramlimits3:
diagramlimits2 = table(content3{:}, 'VariableNames', header2)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by