How to extract two columns of data from a text while skipping certain lines between the data in MATLAB?Is there a foreach in MATLAB? If so, how does it behave if the underlying data changes?MATLAB, Filling in the area between two sets of data, lines in one figureSkip certain words while reading text from a file using matlabHow to extract two columns from a matrix in a sequence of 6 columns in matlabSkipping Lines in Matlab CodeHow to use Matlab to extract certain data from text-fileHow to read number data with strings placed at random line-intervals?extracting data from text file in matlabHow to extract numbers line by line while reading a text file in matlabMATLAB how to skip first line
Are sweatpants frowned upon on flights?
Do multi-engine jets need all engines with equal age to reduce asymmetry in thrust and fuel consumption arising out of deterioration?
Is it alright to add scenes that don’t move the plot forwards much but develop relationships/character?
Blank screen when reusing a previous mail (Mosaico)
How can I throw a body?
How to copy the month value from one Date object to another?
Don't look at what I did there
Why can't I identify major and minor chords?
Convert shapefille to KML
What is the purpose of Strength, Intelligence and Dexterity in Path of Exile?
Can a network vulnerability be exploited locally?
Why does the weaker C–H bond have a higher wavenumber than the C=O bond?
How can weighted averages be calculated for a Dataset summarized with GroupBy
Why is 3/4 a simple meter while 6/8 is a compound meter?
Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?
Historical Daf Yomi calendar
Is it unusual for a math department not to have a mail/web server?
Fixing a blind bolt hole when the first 2-3 threads are ruined?
What checks exist against overuse of presidential pardons in the USA?
Wrong Stamping of UK Visa
RAID0 instead of RAID1 or 5, is this crazy?
Moscow SVO airport, how to avoid scam taxis without pre-booking?
Journal published a paper, ignoring my objections as a referee
What is this "opened" cube called?
How to extract two columns of data from a text while skipping certain lines between the data in MATLAB?
Is there a foreach in MATLAB? If so, how does it behave if the underlying data changes?MATLAB, Filling in the area between two sets of data, lines in one figureSkip certain words while reading text from a file using matlabHow to extract two columns from a matrix in a sequence of 6 columns in matlabSkipping Lines in Matlab CodeHow to use Matlab to extract certain data from text-fileHow to read number data with strings placed at random line-intervals?extracting data from text file in matlabHow to extract numbers line by line while reading a text file in matlabMATLAB how to skip first line
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I get my data as given below (refer to the large data). I need to extract the rows of data after the 19th line the text file. For doing that I can use the following code.
filename= ['f.rpt'];
fid = fopen(filename);
A = textscan(fid, '%f %f','HeaderLines',19) ;
b = A2;
fclose(fid);
However, this will only read and extract the data till the lines containing
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
I would like to skip those lines which do not belong to the two columns of data and extract the data from the rows below as well. The issue is, I can't figure how to skip those lines and extract just the two columns of data. The position of the intermittent data that I want to skip is not constant and changes with different outputs. Is there a way to do that?
********************************************************************************
Field Output Report
Source 1
---------
ODB: ffffff
Step: Step-1
Frame: Increment 7600: Step Time = 6.0000E-011
Loc 1 : Nodal values from source 1
Output sorted by column "CSMAXSCRT General_Contact_Domain".
Field Output reported at nodes for part: PART-1-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
456 1.
455 1.
454 1.
453 1.
452 1.
451 1.
450 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
Field Output reported at nodes for part: PART-3-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
matlab
add a comment |
I get my data as given below (refer to the large data). I need to extract the rows of data after the 19th line the text file. For doing that I can use the following code.
filename= ['f.rpt'];
fid = fopen(filename);
A = textscan(fid, '%f %f','HeaderLines',19) ;
b = A2;
fclose(fid);
However, this will only read and extract the data till the lines containing
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
I would like to skip those lines which do not belong to the two columns of data and extract the data from the rows below as well. The issue is, I can't figure how to skip those lines and extract just the two columns of data. The position of the intermittent data that I want to skip is not constant and changes with different outputs. Is there a way to do that?
********************************************************************************
Field Output Report
Source 1
---------
ODB: ffffff
Step: Step-1
Frame: Increment 7600: Step Time = 6.0000E-011
Loc 1 : Nodal values from source 1
Output sorted by column "CSMAXSCRT General_Contact_Domain".
Field Output reported at nodes for part: PART-1-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
456 1.
455 1.
454 1.
453 1.
452 1.
451 1.
450 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
Field Output reported at nodes for part: PART-3-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
matlab
add a comment |
I get my data as given below (refer to the large data). I need to extract the rows of data after the 19th line the text file. For doing that I can use the following code.
filename= ['f.rpt'];
fid = fopen(filename);
A = textscan(fid, '%f %f','HeaderLines',19) ;
b = A2;
fclose(fid);
However, this will only read and extract the data till the lines containing
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
I would like to skip those lines which do not belong to the two columns of data and extract the data from the rows below as well. The issue is, I can't figure how to skip those lines and extract just the two columns of data. The position of the intermittent data that I want to skip is not constant and changes with different outputs. Is there a way to do that?
********************************************************************************
Field Output Report
Source 1
---------
ODB: ffffff
Step: Step-1
Frame: Increment 7600: Step Time = 6.0000E-011
Loc 1 : Nodal values from source 1
Output sorted by column "CSMAXSCRT General_Contact_Domain".
Field Output reported at nodes for part: PART-1-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
456 1.
455 1.
454 1.
453 1.
452 1.
451 1.
450 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
Field Output reported at nodes for part: PART-3-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
matlab
I get my data as given below (refer to the large data). I need to extract the rows of data after the 19th line the text file. For doing that I can use the following code.
filename= ['f.rpt'];
fid = fopen(filename);
A = textscan(fid, '%f %f','HeaderLines',19) ;
b = A2;
fclose(fid);
However, this will only read and extract the data till the lines containing
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
I would like to skip those lines which do not belong to the two columns of data and extract the data from the rows below as well. The issue is, I can't figure how to skip those lines and extract just the two columns of data. The position of the intermittent data that I want to skip is not constant and changes with different outputs. Is there a way to do that?
********************************************************************************
Field Output Report
Source 1
---------
ODB: ffffff
Step: Step-1
Frame: Increment 7600: Step Time = 6.0000E-011
Loc 1 : Nodal values from source 1
Output sorted by column "CSMAXSCRT General_Contact_Domain".
Field Output reported at nodes for part: PART-1-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
456 1.
455 1.
454 1.
453 1.
452 1.
451 1.
450 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
Field Output reported at nodes for part: PART-2-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
Field Output reported at nodes for part: PART-3-1
Node CSMAXSCRT
Label @Loc 1
---------------------------------
1 1.
2 1.
3 1.
4 1.
5 1.
6 1.
7 1.
8 1.
9 1.
10 1.
11 1.
12 1.
13 1.
14 1.
15 1.
16 1.
17 1.
18 1.
19 1.
20 1.
21 1.
22 1.
23 1.
matlab
matlab
asked Mar 27 at 22:05
rctyrcty
2173 gold badges5 silver badges12 bronze badges
2173 gold badges5 silver badges12 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When using the textscan
method, you can resume scanning. I incorporated that possibility in the following solution. I assumed, that you deal with numeric data, so I directly parsed the cell array output of textscan
accordingly. If that is not wanted, the data appending needs to be modified.
% Read in whole text.
text = fileread('f.txt');
% Initialize result array.
C = [];
% Initialize absolute cursor position.
absPos = 0;
% While absolute cursor position hasn't reached EOF.
while (absPos < numel(text))
% First read -> Skip 19 header lines.
if (absPos == 0)
[data, relPos] = textscan(text, '%f %f', 'HeaderLines', 19);
absPos = absPos + relPos;
% Every further read -> Skip 5 intermediate header lines.
else
[data, relPos] = textscan(text((absPos+1):end), '%f %f', 'HeaderLines', 5);
absPos = absPos + relPos;
end
% Append data.
C = [C; [data:]];
end
I don't want to copy-paste the output to here, because of its length. Please have a look yourself.
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387191%2fhow-to-extract-two-columns-of-data-from-a-text-while-skipping-certain-lines-betw%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When using the textscan
method, you can resume scanning. I incorporated that possibility in the following solution. I assumed, that you deal with numeric data, so I directly parsed the cell array output of textscan
accordingly. If that is not wanted, the data appending needs to be modified.
% Read in whole text.
text = fileread('f.txt');
% Initialize result array.
C = [];
% Initialize absolute cursor position.
absPos = 0;
% While absolute cursor position hasn't reached EOF.
while (absPos < numel(text))
% First read -> Skip 19 header lines.
if (absPos == 0)
[data, relPos] = textscan(text, '%f %f', 'HeaderLines', 19);
absPos = absPos + relPos;
% Every further read -> Skip 5 intermediate header lines.
else
[data, relPos] = textscan(text((absPos+1):end), '%f %f', 'HeaderLines', 5);
absPos = absPos + relPos;
end
% Append data.
C = [C; [data:]];
end
I don't want to copy-paste the output to here, because of its length. Please have a look yourself.
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
add a comment |
When using the textscan
method, you can resume scanning. I incorporated that possibility in the following solution. I assumed, that you deal with numeric data, so I directly parsed the cell array output of textscan
accordingly. If that is not wanted, the data appending needs to be modified.
% Read in whole text.
text = fileread('f.txt');
% Initialize result array.
C = [];
% Initialize absolute cursor position.
absPos = 0;
% While absolute cursor position hasn't reached EOF.
while (absPos < numel(text))
% First read -> Skip 19 header lines.
if (absPos == 0)
[data, relPos] = textscan(text, '%f %f', 'HeaderLines', 19);
absPos = absPos + relPos;
% Every further read -> Skip 5 intermediate header lines.
else
[data, relPos] = textscan(text((absPos+1):end), '%f %f', 'HeaderLines', 5);
absPos = absPos + relPos;
end
% Append data.
C = [C; [data:]];
end
I don't want to copy-paste the output to here, because of its length. Please have a look yourself.
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
add a comment |
When using the textscan
method, you can resume scanning. I incorporated that possibility in the following solution. I assumed, that you deal with numeric data, so I directly parsed the cell array output of textscan
accordingly. If that is not wanted, the data appending needs to be modified.
% Read in whole text.
text = fileread('f.txt');
% Initialize result array.
C = [];
% Initialize absolute cursor position.
absPos = 0;
% While absolute cursor position hasn't reached EOF.
while (absPos < numel(text))
% First read -> Skip 19 header lines.
if (absPos == 0)
[data, relPos] = textscan(text, '%f %f', 'HeaderLines', 19);
absPos = absPos + relPos;
% Every further read -> Skip 5 intermediate header lines.
else
[data, relPos] = textscan(text((absPos+1):end), '%f %f', 'HeaderLines', 5);
absPos = absPos + relPos;
end
% Append data.
C = [C; [data:]];
end
I don't want to copy-paste the output to here, because of its length. Please have a look yourself.
When using the textscan
method, you can resume scanning. I incorporated that possibility in the following solution. I assumed, that you deal with numeric data, so I directly parsed the cell array output of textscan
accordingly. If that is not wanted, the data appending needs to be modified.
% Read in whole text.
text = fileread('f.txt');
% Initialize result array.
C = [];
% Initialize absolute cursor position.
absPos = 0;
% While absolute cursor position hasn't reached EOF.
while (absPos < numel(text))
% First read -> Skip 19 header lines.
if (absPos == 0)
[data, relPos] = textscan(text, '%f %f', 'HeaderLines', 19);
absPos = absPos + relPos;
% Every further read -> Skip 5 intermediate header lines.
else
[data, relPos] = textscan(text((absPos+1):end), '%f %f', 'HeaderLines', 5);
absPos = absPos + relPos;
end
% Append data.
C = [C; [data:]];
end
I don't want to copy-paste the output to here, because of its length. Please have a look yourself.
answered Mar 28 at 6:10
HansHirseHansHirse
3,2335 gold badges12 silver badges31 bronze badges
3,2335 gold badges12 silver badges31 bronze badges
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
add a comment |
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
Wow! Thank you so much! That's it!
– rcty
Mar 28 at 13:41
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387191%2fhow-to-extract-two-columns-of-data-from-a-text-while-skipping-certain-lines-betw%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown