Mark and replace strings from my input file

2 vues (au cours des 30 derniers jours)
Philipp Mueller
Philipp Mueller le 11 Avr 2017
Hello,
I have an input file. Its a .txt-File. From this input .txt File i get my data for my matlab calculation. Is it possible that i mark my sigma_x or sigma_m in my input .txt File with a underline _ or * or something else so i can replace this sigma_x in my matlab Code with \sigma_{x}. I hope you understand what i mean. Thank you for your help.
For example this "r_diagramheaderSigmaX=Rainflow-Matrix sigma_x" in my input
********************Plot Page Options and Settings******
pageheader=dummy0
*******************Diagram Options SigmaX************
r_diagramheaderSigmaX=Rainflow-Matrix sigma_x
r_labelordinateSigmaX=Amplitude sigma_a
r_labelabscissaSigmaX=Mittelwert sigma_m
r_abscissaMinSigmaX=8.6625
r_abscissaMaxSigmaX=28.4625
This is my Code:
r_inputdataSigmaX=[;];
r_inputdataSigmaY=[;];
r_inputdataTau=[;];
w_inputdataTau=[;];
w_inputdataSigmaY=[;];
w_inputdataSigmaX=[;];
cuttofflinesSigmaX=[;];
cuttofflinesSigmaY=[;];
cuttofflinesTau=[;];
r_inputdata_logic=zeros(1,3);
w_inputdata_logic=zeros(1,3);%[0;0;0]; %zeros(m,n)
inputdata_cuttofflines_logic=zeros(1,3);%[0;0;0];
default_value_z=1e8; %hier setze defaultmässig die z Komponente/Wert der Cutofflinien
row1=0;
row2=0;
row3=0;
index_counter=1;
t=0;
%Einlese Prozedere
wholecontent = fileread('MatlabExport_2.txt')
sections = regexp(wholecontent, '\*+([^*]+)\*+([^*]+)', 'tokens')
for section = sections
switch(strtrim(section{1}{1}))
case 'Plot Page Options and Settings'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
plotpageSettings = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Die Diagram Options gelten jeweils für rainflow und woehler
case 'Diagram Options SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Options SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Diagram Options Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Woehler Lines SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,1) = 1;
case 'Woehler Lines SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,2) = 1;
case 'Woehler Lines Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
w_diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
w_inputdata_logic(1,3) = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Options SigmaX'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsSigmaX = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Rainflow Options SigmaY'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsSigmaY = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
case 'Rainflow Options Tau'
keyvalues = regexp(section{1}{2}, '([^\n\r=]+)=([^\n\r=]+)', 'tokens')
r_diagramoptionsTau = cell2table(vertcat(keyvalues{:}), 'VariableNames', {'Key', 'Value'})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Cutofflines SigmaX'
cuttofflinesSigmaX = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,1) = 1;
case 'Rainflow Cutofflines SigmaY'
cuttofflinesSigmaY = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,2) = 1;
case 'Rainflow Cutofflines Tau'
cuttofflinesTau = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
inputdata_cuttofflines_logic(1,3) = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'StressSpectrum Data SigmaX'
w_inputdataSigmaX = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
case 'StressSpectrum Data SigmaY'
w_inputdataSigmaY = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
case 'StressSpectrum Data Tau'
w_inputdataTau = cell2mat(textscan(section{1}{2}, '%f%f', 'HeaderLines', 1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'Rainflow Data SigmaX'
r_inputdataSigmaX = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,1) = 1;
case 'Rainflow Data SigmaY'
r_inputdataSigmaY = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,2) = 1;
case 'Rainflow Data Tau'
r_inputdataTau = cell2mat(textscan(section{1}{2}, '%f%f%f', 'HeaderLines', 1))
r_inputdata_logic(1,3) = 1;
otherwise
warning('Unknown section ERROR: %s', section{1}{1})
end
end
diagramheader=diagramoptionsSigmaX.Value(strcmp(diagramoptionsSigmaX.Key, 'r_diagramheaderSigmaX'))
labelabscissa=diagramoptionsSigmaX.Value(strcmp(diagramoptionsSigmaX.Key, 'r_labelabscissaSigmaX'))
labelordinate=diagramoptionsSigmaX.Value(strcmp(diagramoptionsSigmaX.Key, 'r_labelordinateSigmaX'))

Réponses (0)

Catégories

En savoir plus sur Vibration Analysis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by