How do I split this data into different column and write it back in a text file with an extention .bdf?
16 views (last 30 days)
I would like to split this data into different columns without any emoty cells and write it into a text file and save it as .bdf. Can you helps me ?
Edited: dpb on 6 Jul 2022
modifies MAT1 as per request...
Now, we're still at a loss as to what to write -- you complain you can't remove empty columns, but say to write back in "the same original format" which would be comma-delimited with trailing empty fields.
So, which is it???
LATER RESUMPTION AFTER REFLECTION ON LIKELY SCENARIOS
OK, so presuming to take the "original" at face value, then next step is to replace the MAT1 section in the overall array and output the updated array --
M=join(M,','); % put back into csv form by line
ix=startsWith(data,'MAT1'); % locate in original array
data(ix)=M; % and replace with new/revised set
writematrix(data,'mat1.fem') % and write out
NB: I changed filename in last to not overwirte the original; salt to suit.
A minor efficiency improvement would be to compute the index vector ix first and use it to select M in the second line above as well -- saves doing same thing twice't as is in above as given.
More Answers (3)
Edited: dpb on 5 Jul 2022
So, what is this -- the content of some file, an array of text, a cell array... ??
What are we looking at here?
If it's a text file, simply
will provide a cell array of the content w/o missing column(s).
Now, what is a ".bdf" file format to write???
An alternative is to not bring in the empty cells to begin with -- use the import options object:
and your data array won't have missing variables in the first place.
We're still awaiting word on the output format to finish up...
Karim on 5 Jul 2022
Edited: Karim on 5 Jul 2022
Hi @Adeline War, assumig you have the data in a string array, you can use the procedure below.
MyData = ["MAT1,88813,210000.0,,0.3,7.85e-09,,,,"
% replace the comma
MyData = strrep(MyData,","," ")
% delete double spaces
MyData = regexprep(MyData,' +',' ')
% print the data to .bdf file
MyFile = fopen('test.bdf','w+');