eliminate a letter after getting a matrix data from text file
Show older comments
Hello, I am collecting data from a text file. This data is rearraged accoding to the position of the columns (e.g., # HHE HHN HHZ) by using texline1, textline2 and so son.
textline1 = '# HNE HNN HNZ';
textline2 = '# HNE HNZ HNN';
textline3 = '# HNN HNE HNZ';
textline4 = '# HNN HNZ HNE';
textline5 = '# HNZ HNE HNN';
textline6 = '# HNZ HNN HNE';
I getting different information from the text file and part of one information (estated above) is as follow and collects all the numerical data until the end of the file after "# HHE HHN HHZ" as described in the script below
Part of the text file:
5. ACCELERATION DATA
# HHE HHN HHZ
-0.02104708 -0.02134472 0.00412299
-0.00340606 0.08357343 0.02083563
-0.02940362 0.00093856 0.0050514
. . .
. . .
. . .
Part of the script:
%First mixed data%
if index==0
index = strcmp(tline,textline1); %%EO NS UD
if index ==1; index=1; end
elseif index ==1
tmp=sscanf(tline,'%f %f %f %f');
tmp1 = [tmp(1); tmp(2); tmp(3)]; % rearrange to EO=X NS=Y UD=Y
Output = [Output; tmp1'];
end
This scripts works perfectly capturing the "Ouput" data after "# HHE HHN HHZ". The only problem is that some text files present the following case:
5. ACCELERATION DATA
# HHE HHN HHZ
T
-0.02104708 -0.02134472 0.00412299
-0.00340606 0.08357343 0.02083563
-0.02940362 0.00093856 0.0050514
A "T" letter ruins all the collection of the numerical data after "# HHE HHN HHZ". There is a way in which I can only add and aditional "script line" after "tmp=sscanf(tline,'%f %f %f %f');" in the previous script which eliminates the letter "T" and capture the data "tmp1" to rearrange it according to the textline (e.g., textline1) withouth making too many changes in the script. So, for the case in which a letter "T" appears after "# HHE HHN HHZ" just get rid of it and only capture the numerical values.
Thank you for your response
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!