Split cell each 13 characters
Ältere Kommentare anzeigen
Hello everyone,
I'm creating a code that reads a txt file, stores it as a matrix and keeps only a range of value. This first part is done, code below. So i have a matrix of about 32x1
I would like to split my values so each one goes into a cell, so i have a 32x6 matrix. Thing is, the only thing that can split the values is their lenght, as they are all made of 13 characters (exemple right below)
-0.198181E-10-0.100000E+01-0.173525E-10 0.445807E-16-0.142817E-10 0.122740E-11
0.100000E+01-0.333333E+00-0.198181E-10-0.100000E+01-0.198181E-10-0.173525E-10
-0.167526E-10-0.100000E+01-0.195269E-10 0.325840E-11-0.171677E-10 0.139359E-11
0.100000E+01-0.333333E+00-0.167526E-10-0.100000E+01-0.195269E-10-0.167526E-10
Is there a way to split this at each 13 characters ?
Thanks for any help
Matt
file = 'G:\\Matthieu\\DangVan\\QuarterCube\\Job1_job1.t19';
A = textscan(fopen(file),'%s','delimiter', '\n');
starter='=beg=52300 (Element Integration Point Values) ';
ender='=beg=52401 (Nodal Results) ';
stressloc1=find(strcmp(A{1,1},starter))+1 %find start of my range
stressloc2=find(strcmp(A{1,1},ender))-2 %find end of my range
stressvector = A{1,1}([stressloc1:stressloc2],1); % Extract rows
Akzeptierte Antwort
Weitere Antworten (2)
It would be usful, if you post your input data and the wanted output. Currently I find the information
- matrix of about 32x1
- each one goes into a cell
- so i have a 32x6 matrix
- Example (which neither a 31x1 matrix, nor a cell, nor a 32x6 matrix nor is it clear, if the shown code produces it):
-0.198181E-10-0.100000E+01-0.173525E-10 0.445807E-16-0.142817E-10 0.122740E-11
0.100000E+01-0.333333E+00-0.198181E-10-0.100000E+01-0.198181E-10-0.173525E-10
-0.167526E-10-0.100000E+01-0.195269E-10 0.325840E-11-0.171677E-10 0.139359E-11
0.100000E+01-0.333333E+00-0.167526E-10-0.100000E+01-0.195269E-10-0.167526E-10
5. Some code which produces something, but what?
So what exactly should be split to what?
A bold guess:
C = '-0.198181E-10-0.100000E+01-0.173525E-10 0.445807E-16-0.142817E-10 0.122740E-11';
D = sscanf(C, '%13E');
format longg
disp(D)
1 Kommentar
Matthieu Aoun
am 17 Dez. 2021
Matthieu Aoun
am 17 Dez. 2021
Bearbeitet: Matthieu Aoun
am 17 Dez. 2021
2 Kommentare
"It seems that I wasn't clear enough"
It was quite clear, which is why once you uploaded your file two hours ago I showed you here how to import it as a fixed-width text file. The output is a 32x6 numeric array, which seems to match what you are expecting.
Is there a particular reason why the code I gave in my comment does not work for you?
Matthieu Aoun
am 17 Dez. 2021
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!