Reading in 8 and then 16 characters using regexp on one line - NASTRAN data file

1 Ansicht (letzte 30 Tage)
So I'm writing a program that reads in NASTRAN data file entries. Usually you could read it in 8 characters at a time to get the right numbers, or if it's separated by commas I could use regexp split. However, sometimes it looks like this:
The * entries are 8 characters and then 16 for everything after. The other examples shown like PBAR and CTRIA3 can be read in 8 characters at a time throughout. If I have it so that the first line is a 1x60 char in the first column of a 700000x2 cell and the second line is a 1x44 char in the second column, how can I separate the values into a 1x5 cell in the first column and a 1x4 cell in the second column of a different variable?
I'm mostly asking how to read in 8 characters for the first word and then 16 for every number after if I normally do this for 8 characters:
tok=regexp(all,'.{1,8}','match');
I'm doing the following if "all" is the 700000x2 cell and separate does something like the line above depending on the type of entry:
[~, width]=size(all);
for i=1:width
All(:,i)=cellfun(@separate,all(:,i), 'UniformOutput', false);
end
Any advice on how to do this better is appreciated as well. Also note that it isn't always 4 numbers after the entry name (it can be up to 9 but sometimes only 1)

Akzeptierte Antwort

Megna Hari
Megna Hari am 7 Aug. 2014
Nevermind you guys, I figured it out:
a=lin(1:8);
b=lin(9:length(lin));
tok1=regexp(b,'.{1,16}','match');
tok=horzcat(a, tok1);
If you have a better way to do it you can still comment below :)

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by