How do I split this data into different column and write it back in a text file with an extention .bdf?
4 ビュー (過去 30 日間)
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 ?
編集済み: dpb 2022 年 7 月 6 日
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.
その他の回答 (3 件)
編集済み: dpb 2022 年 7 月 5 日
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 2022 年 7 月 5 日
編集済み: Karim 2022 年 7 月 5 日
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+');