Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Obtain a New line in a buffer
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have a mesh file name "conesphere", and it contains some numbers like this:
$Nodes
5
1 3.306 0 0
2 2.9754 0 0
3 2.9754 1.356193216322807 0
4 2.9754 0.9589734198610512 0.9589734198610511
5 2.9754 8.304014148598576e-17 1.356193216322807
$EndNodes
So, I am trying to have these numbers in the same order (without $Nodes and $EndNodes words) like this:
1 3.306 0 0
2 2.9754 0 0
3 2.9754 1.356193216322807 0
4 2.9754 0.9589734198610512 0.9589734198610511
5 2.9754 8.304014148598576e-17 1.356193216322807
However, when I use the code as shown in below, I am getting this result, and it seems like I have a new line issue:
1 3.306 0 02 2.9754 0 03 2.9754 1.356193216322807 04 2.9754 0.9589734198610512 0.95897341986105115 2.9754 8.304014148598576e-17 1.356193216322807
if true
% fid = fopen('conesphere.msh', 'rt');
s = textscan(fid, '%s', 'delimiter', '\n');
idx1 = find(strcmp(s{1}, '$Nodes'), 1, 'first');
idx2 = find(strcmp(s{1}, '$EndNodes'), 1, 'first');
buffer = s{1}(idx1+2:idx2-1);
dataTxt = sprintf('%s\n',buffer{:});
fileID = fopen('nodes.txt','w');
fprintf(fileID,dataTxt);
fclose(fileID);
end
0 Commenti
Risposte (1)
Walter Roberson
il 9 Feb 2017
I suggest you use fileread() to read in the exact file as a continuous string. You can use strfind to get the location of interest and extract the substring and fwrite it to a file.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!