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

조회 수: 1 (최근 30일)
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)

채택된 답변

Megna Hari
Megna Hari 2014년 8월 7일
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 :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by