Reading and finding string in a text (.TXT) file containing string and numerical data

35 views (last 30 days)
I am trying to read data from a text file (attachment). This is a typical summary output from a CFD simulation which has a short description in the first couple of lines, then has columns of numerical data after that. I have always handled CFD ouput using excel but it seems like working with .TXT files as output is easier and the program that I use for CFD computations generates output in .TXT fromat. However, one issue that I constantly face when dealing with .TXT files is that it is not clear to me in which format the data is read into the machine, how the existing commands hanlde the data, or even which command will be the most suitable one for the data format at hand. The good thing is that the data files will always look like this, so if I knew which command to use, I wouldn't need to switich to another one.
What I need to know is this:
  1. Which command to use, and I have tried all of these: readtable, readmatrix, textread & textscan but each one has a slight quirk that makes it unsuitable for the kind of search that I need to conduct or it is necessary to use more than one command to deal with both the text and the numerical data. In case of textread, e.g., the data seems to be read in the form of a single column cell array, and NONE of the common string search commands seem to work here (contains, strcmp, strfind).
If I use textread:
InText=textread(InputFile,'%q')
the input data is in the form of a 670x1 cell array and none of the search commands find the string I am looking for.
If, instead, I use textscan, as suggested by MATLAB, the ouput is not shown, but MATLAB indicates that it is a 6X1 cell array.
The search commands again will not work.
  1. How to find the location of a certain srting in the first lines of the text. In case of the file in attachmentm that string would e.g. be 'Volume Average', but the list may include a handful of more options. This will then determine how the code will proceed with further calculations. I tried
  2. Location of the headers of the numerical data, as in line 5 of the attached file: 'Eta0 (Pa*s)', 'Velocity magnitude (m/s)', 'abs(u2) (m/s)' and so on. This will then tell the program to treat each numerical column accordingly. It is tempting to just read the numerical part and assume the position of each column, but one should not forget that each user may have saved the output file in a different sequence of columns and therefore the best practice is to fully automate the search for values by finding the assigned name for each column. The good news is that the names are fixed and never change their format.
here is the whole script:
clc; format long g; clear all;
% Reading the inout file(s)
[FN,FP] = uigetfile('*.txt','MultiSelect','on');
if isequal(FN,0)
disp('No files selcted');
return
else
disp(['Files selected:', fullfile(FP,FN)]);
end
if class(FN) =='char', FN={FN}; end
FN=FN';
jCounter=0; ParaVal=[];
Text2Find='Volume Average';
for iF=1:size(FN,1)
InFile=FN{iF};
%InText=textscan(InFile,'%q')
InText=textread(InFile,'%q')
%InTab=readtable(InFile,'VariableNamingRule' , 'preserve');
ParaIdx=find(contains(InText,Text2Find))
find(strcmp(InText,'Velocity Magnitude' ))
%strfind(InText,Text2Find)
end
Thanks,
Saeid
  3 Comments
Saeid
Saeid on 24 Dec 2023
The format of all the files generated is the same, in that they all have 5-6 rows of text, then the headers row (Eta0(Pa * s) etc.) which is also text, then the numerical part. There are typically three files but one of them has fewer number of columns compared to the other two, and some headers may be different.
I don't see any empty values in the last column.
The first column is a equidistance logarithmic array, and the values of 100, 10, etc. are just the right decade values.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 24 Dec 2023
Edited: Star Strider on 26 Dec 2023
The file appears to contain two duplicate horizontally-concatenated matrices, other than for the first column. This is not an easy file to deal with, however it is possible. I just used fgetl to get tthe first four lines, saving them as a cell array. The fifth line became the header lines for the table, created by readtable and extracting them and then assigning them as variable names turned out to be relatively straightforrward. There are duplicated names and duplicated values, so I separated them into two tables (duplicating the first column from the original table in the second table), since duplicated variable names are not permitted.
Try this —
File = 'Rushton 4 Blad...ge Values.txt';
F = fileread(File)
F =
'% Model: Rushton_4_Blades_Cross_Eta0_Ramp.mph % Version: COMSOL 6.2.0.278 % Date: Dec 24 2023, 11:04 % Table: Table 3 - Volume Average 1 % Eta0 (Pa*s) Velocity magnitude (m/s) abs(u2) (m/s) abs(v2) (m/s) abs(w2) (m/s) Shear rate (1/s) Turbulent kinetic energy (m^2/s^2) Turbulent dissipation rate (m^2/s^3) Velocity magnitude (m/s) abs(u2) (m/s) abs(v2) (m/s) abs(w2) (m/s) Shear rate (1/s) Turbulent kinetic energy (m^2/s^2) Turbulent dissipation rate (m^2/s^3) 100 0.04615239831437706 0.028946653908979308 0.02919333647852305 0.005137220379201468 2.6321200223023355 3.6098375833972445 2.896787166438316 0.04615239831437706 0.028946653908979308 0.02919333647852305 0.005137220379201468 2.6321200223023355 3.6098375833972445 2.896787166438316 74.98942093324558 0.04673804964081588 0.02931709705101385 0.02956469457131861 0.005129994295323251 2.635726623241281 2.8394996678614848 2.3878324910912068 0.04673804964081588 0.02931709705101385 0.02956469457131861 0.005129994295323251 2.635726623241281 2.8394996678614848 2.3878324910912068 56.23413251903491 0.04739239039126288 0.029728674214441787 0.0299778598421239 0.005135194980231561 2.6415843515609256 2.215694241372109 1.9436426901724122 0.04739239039126288 0.029728674214441787 0.0299778598421239 0.005135194980231561 2.6415843515609256 2.215694241372109 1.9436426901724122 42.169650342858226 0.04810642339695835 0.03017743104904372 0.030428632998444016 0.005149111736697798 2.6494866573949736 1.7174535265555064 1.5681314165726818 0.04810642339695835 0.03017743104904372 0.030428632998444016 0.005149111736697798 2.6494866573949736 1.7174535265555064 1.5681314165726818 31.622776601683793 0.048809599374448426 0.03061932923815537 0.03087213061907828 0.00516770536022979 2.658594511795719 1.3194798760340252 1.2491875272317328 0.048809599374448426 0.03061932923815537 0.03087213061907828 0.00516770536022979 2.658594511795719 1.3194798760340252 1.2491875272317328 23.71373705661655 0.04949885428178431 0.031052961152430607 0.031306432302950764 0.005190237084122372 2.6689295364770036 1.0052533227091993 0.9845784290716366 0.04949885428178431 0.031052961152430607 0.031306432302950764 0.005190237084122372 2.6689295364770036 1.0052533227091993 0.9845784290716366 17.78279410038923 0.050200281540114966 0.03149442400566759 0.03174828572633424 0.005219243328527017 2.6809859664479947 0.759940084968403 0.7699010127209062 0.050200281540114966 0.03149442400566759 0.03174828572633424 0.005219243328527017 2.6809859664479947 0.759940084968403 0.7699010127209062 13.33521432163324 0.050918089735444906 0.03194724481400102 0.03220024202154808 0.0052572390438078665 2.6951925661522624 0.5702179804811636 0.5986749692334613 0.050918089735444906 0.03194724481400102 0.03220024202154808 0.0052572390438078665 2.6951925661522624 0.5702179804811636 0.5986749692334613 10 0.05174265740974295 0.03246783446262243 0.03271909334629274 0.005313406004304652 2.7131229166876527 0.4242212733325033 0.4632430289678753 0.05174265740974295 0.03246783446262243 0.03271909334629274 0.005313406004304652 2.7131229166876527 0.4242212733325033 0.4632430289678753 7.498942093324558 0.05265105712424322 0.033041725598873445 0.03328967416888072 0.005396726742027751 2.73550251611291 0.31272417834971905 0.35701445135187515 0.05265105712424322 0.033041725598873445 0.03328967416888072 0.005396726742027751 2.73550251611291 0.31272417834971905 0.35701445135187515 5.623413251903491 0.053632448532638315 0.0336616441379261 0.0339032133352275 0.005525490757288563 2.763535705084588 0.22807337870319955 0.27396386734189687 0.053632448532638315 0.0336616441379261 0.0339032133352275 0.005525490757288563 2.763535705084588 0.22807337870319955 0.27396386734189687 4.216965034285822 0.05465877657758982 0.034308231863556804 0.03453823546905157 0.005728071273347786 2.7989116654435855 0.1640936706039396 0.208848741101647 0.05465877657758982 0.034308231863556804 0.03453823546905157 0.005728071273347786 2.7989116654435855 0.1640936706039396 0.208848741101647 3.1622776601683795 0.05572773702463254 0.03497423544885796 0.035186233309994944 0.0060440168535349685 2.8442160753176555 0.11605014446590997 0.15777019494409028 0.05572773702463254 0.03497423544885796 0.035186233309994944 0.0060440168535349685 2.8442160753176555 0.11605014446590997 0.15777019494409028 2.371373705661655 0.05682156614258934 0.035630311354002055 0.03581573447086524 0.006542652148277501 2.9041794218196877 0.08031884649671582 0.11779104056600928 0.05682156614258934 0.035630311354002055 0.03581573447086524 0.006542652148277501 2.9041794218196877 0.08031884649671582 0.11779104056600928 1.7782794100389228 0.05788045069036774 0.0362312722772817 0.03638821755402852 0.007191679268200796 2.9734786038115404 0.06261499292840927 0.09428857810987086 0.05788045069036774 0.0362312722772817 0.03638821755402852 0.007191679268200796 2.9734786038115404 0.06261499292840927 0.09428857810987086 1.333521432163324 0.05911589584468429 0.03687746882088943 0.03700048661416649 0.008211693723973422 3.0651290837466387 0.0490871577337868 0.07444670797302855 0.05911589584468429 0.03687746882088943 0.03700048661416649 0.008211693723973422 3.0651290837466387 0.0490871577337868 0.07444670797302855 1 0.06167276513439243 0.03804744712686018 0.03810034683511643 0.010518035846065856 3.2478068840124004 0.025370083135180146 0.05001891196066428 0.06167276513439243 0.03804744712686018 0.03810034683511643 0.010518035846065856 3.2478068840124004 0.025370083135180146 0.05001891196066428 0.7498942093324559 0.06458154977124218 0.039461450914178346 0.0394668862227727 0.012758022645317741 3.4607241344196518 0.017940247035202053 0.039333757843929104 0.06458154977124218 0.039461450914178346 0.0394668862227727 0.012758022645317741 3.4607241344196518 0.017940247035202053 0.039333757843929104 0.5623413251903491 0.07042087170735499 0.04259948180422956 0.04256315263526966 0.015905176635980733 3.792220799431052 0.013195621464344399 0.03234195303344573 0.07042087170735499 0.04259948180422956 0.04256315263526966 0.015905176635980733 3.792220799431052 0.013195621464344399 0.03234195303344573 0.4216965034285822 0.08130889262787269 0.04872009150676633 0.04866031837302463 0.02056038506743542 4.246503473323532 0.010165920978789458 0.02797188966149063 0.08130889262787269 0.04872009150676633 0.04866031837302463 0.02056038506743542 4.246503473323532 0.010165920978789458 0.02797188966149063 0.31622776601683794 0.0965363056664072 0.05732856857674067 0.05727569806215155 0.026590936910714718 4.772823824892596 0.008128313835830897 0.024742549333272874 0.0965363056664072 0.05732856857674067 0.05727569806215155 0.026590936910714718 4.772823824892596 0.008128313835830897 0.024742549333272874 0.23713737056616552 0.11455823281127059 0.06749815907957529 0.0674633889912467 0.03344056543703339 5.325763251473064 0.006684245759588636 0.02198181026337845 0.11455823281127059 0.06749815907957529 0.0674633889912467 0.03344056543703339 5.325763251473064 0.006684245759588636 0.02198181026337845 0.1778279410038923 0.13611332872750542 0.07989280561341841 0.07987806612222816 0.04069225868878538 5.867120502525145 0.005655463157169491 0.019520847027148947 0.13611332872750542 0.07989280561341841 0.07987806612222816 0.04069225868878538 5.867120502525145 0.005655463157169491 0.019520847027148947 0.1333521432163324 0.1640487384827493 0.09698958885001317 0.09699076930613626 0.04697374654591694 6.32712194878707 0.004874186426190038 0.01715445976935903 0.1640487384827493 0.09698958885001317 0.09699076930613626 0.04697374654591694 6.32712194878707 0.004874186426190038 0.01715445976935903 0.1 0.1943360704325999 0.11770896605555266 0.11776801961599513 0.046689418714616814 6.59423487141189 0.004230013863249288 0.014571977596269443 0.1943360704325999 0.11770896605555266 0.11776801961599513 0.046689418714616814 6.59423487141189 0.004230013863249288 0.014571977596269443 0.07498942093324558 0.2207250424855672 0.1360989496602475 0.13623593811893672 0.04351841865639921 6.707179359594688 0.003681215361917449 0.012336448138242518 0.2207250424855672 0.1360989496602475 0.13623593811893672 0.04351841865639921 6.707179359594688 0.003681215361917449 0.012336448138242518 0.05623413251903491 0.24448997351656934 0.15225585590543655 0.15243796728255854 0.0404442363744368 6.764276518861652 0.0031951274852746853 0.010500334934774452 0.24448997351656934 0.15225585590543655 0.15243796728255854 0.0404442363744368 6.764276518861652 0.0031951274852746853 0.010500334934774452 0.042169650342858224 0.2639851434996848 0.16530817515523302 0.1654884754750192 0.0376474165255942 6.759769962072446 0.0027940364629126108 0.009005645303266224 0.2639851434996848 0.16530817515523302 0.1654884754750192 0.0376474165255942 6.759769962072446 0.0027940364629126108 0.009005645303266224 0.03162277660168379 0.27898219378325595 0.17528307584280345 0.17543714257336682 0.03512448016499392 6.681493699317322 0.0024925399383485328 0.007832078819644274 0.27898219378325595 0.17528307584280345 0.17543714257336682 0.03512448016499392 6.681493699317322 0.0024925399383485328 0.007832078819644274 0.023713737056616554 0.2895319611176411 0.18226356283749 0.1823847755529623 0.03331233925391496 6.571237959414365 0.0022808061360037658 0.00697637242831832 0.2895319611176411 0.18226356283749 0.1823847755529623 0.03331233925391496 6.571237959414365 0.0022808061360037658 0.00697637242831832 0.01778279410038923 0.2968609291018904 0.18707529662460748 0.18716746808547974 0.0323884416428399 6.523116567176665 0.0021355643251627 0.0064195915913036255 0.2968609291018904 0.18707529662460748 0.18716746808547974 0.0323884416428399 6.523116567176665 0.0021355643251627 0.0064195915913036255 0.01333521432163324 0.30324993595084165 0.1912611884793794 0.1913271640854985 0.031615624906042826 6.503732569175253 0.0020139368759561718 0.005991159829871907 0.30324993595084165 0.1912611884793794 0.1913271640854985 0.031615624906042826 6.503732569175253 0.0020139368759561718 0.005991159829871907 0.01 0.3085463072362381 0.19472107343423692 0.19476617546744793 0.031032556510266384 6.48759933664475 0.0019169546471227968 0.005665832492002017 0.3085463072362381 0.19472107343423692 0.19476617546744793 0.031032556510266384 6.48759933664475 0.0019169546471227968 0.005665832492002017 0.007498942093324558 0.314163614775912 0.19837961007760585 0.1984163809261665 0.03039447339138001 6.435936194584802 0.0018550716705336252 0.005433296218904341 0.314163614775912 0.19837961007760585 0.1984163809261665 0.03039447339138001 6.435936194584802 0.0018550716705336252 0.005433296218904341 0.005623413251903491 0.3202722710222204 0.20235900378924848 0.20239077839603536 0.029550755728094357 6.367382948196319 0.0018130747957006397 0.0052545389238258895 0.3202722710222204 0.20235900378924848 0.20239077839603536 0.029550755728094357 6.367382948196319 0.0018130747957006397 0.0052545389238258895 0.004216965034285823 0.32646443503626604 0.20639124120431687 0.20641899057201293 0.02861848204362823 6.298849567849815 0.001782033579249516 0.005109936138749566 0.32646443503626604 0.20639124120431687 0.20641899057201293 0.02861848204362823 6.298849567849815 0.001782033579249516 0.005109936138749566 0.0031622776601683794 0.3324520117119519 0.21028678318634123 0.21031109744314574 0.027698664516245926 6.234247673140273 0.001756139364256116 0.004982523590673373 0.3324520117119519 0.21028678318634123 0.21031109744314574 0.027698664516245926 6.234247673140273 0.001756139364256116 0.004982523590673373 0.0023713737056616554 0.33810952247708476 0.21396391311038787 0.21398539472060354 0.026828592172285635 6.173747015265272 0.0017330078817331825 0.0048663240794430615 0.33810952247708476 0.21396391311038787 0.21398539472060354 0.026828592172285635 6.173747015265272 0.0017330078817331825 0.0048663240794430615 0.0017782794100389228 0.3434510977958674 0.21743255058474328 0.2174512876156701 0.02600993612506495 6.117227672761589 0.001711605063564812 0.004758191577134615 0.3434510977958674 0.21743255058474328 0.2174512876156701 0.02600993612506495 6.117227672761589 0.001711605063564812 0.004758191577134615 0.001333521432163324 0.34849054583005035 0.22070233833586586 0.2207184324195147 0.025241293096729636 6.0644183947502315 0.001691357516863304 0.004656922207605316 0.34849054583005035 0.22070233833586586 0.2207184324195147 0.025241293096729636 6.0644183947502315 0.001691357516863304 0.004656922207605316 0.001 0.3532348045693875 0.2237783743046334 0.22379200612473762 0.02452188824938115 6.0148725425880185 0.0016719018996698407 0.004561692882386946 0.3532348045693875 0.2237783743046334 0.22379200612473762 0.02452188824938115 6.0148725425880185 0.0016719018996698407 0.004561692882386946 '
fidi = fopen(File, 'rt');
k = 1;
while ~feof(fidi)
OneLine = fgetl(fidi);
if strcmp(OneLine(1), '%')
HeaderLine{k,:} = OneLine;
else
break
end
k = k+1;
end
fclose(fidi);
HeaderLine(1:k-2)
ans = 4×1 cell array
{'% Model: Rushton_4_Blades_Cross_Eta0_Ramp.mph'} {'% Version: COMSOL 6.2.0.278' } {'% Date: Dec 24 2023, 11:04' } {'% Table: Table 3 - Volume Average 1' }
HL = k-1;
VN = strsplit(HeaderLine{end}(3:end), ' ');
T1 = readtable(File, 'VariableNamingRule','preserve', 'CommentStyle','%', 'HeaderLines',HL);
T1a = T1(:,1:8);
T1a.Properties.VariableNames = VN(1:8)
T1a = 41×8 table
Eta0 (Pa*s) Velocity magnitude (m/s) abs(u2) (m/s) abs(v2) (m/s) abs(w2) (m/s) Shear rate (1/s) Turbulent kinetic energy (m^2/s^2) Turbulent dissipation rate (m^2/s^3) ___________ _________________________ _____________ ______________ ______________ _________________ __________________________________ ____________________________________ 100 0.046152 0.028947 0.029193 0.0051372 2.6321 3.6098 2.8968 74.989 0.046738 0.029317 0.029565 0.00513 2.6357 2.8395 2.3878 56.234 0.047392 0.029729 0.029978 0.0051352 2.6416 2.2157 1.9436 42.17 0.048106 0.030177 0.030429 0.0051491 2.6495 1.7175 1.5681 31.623 0.04881 0.030619 0.030872 0.0051677 2.6586 1.3195 1.2492 23.714 0.049499 0.031053 0.031306 0.0051902 2.6689 1.0053 0.98458 17.783 0.0502 0.031494 0.031748 0.0052192 2.681 0.75994 0.7699 13.335 0.050918 0.031947 0.0322 0.0052572 2.6952 0.57022 0.59867 10 0.051743 0.032468 0.032719 0.0053134 2.7131 0.42422 0.46324 7.4989 0.052651 0.033042 0.03329 0.0053967 2.7355 0.31272 0.35701 5.6234 0.053632 0.033662 0.033903 0.0055255 2.7635 0.22807 0.27396 4.217 0.054659 0.034308 0.034538 0.0057281 2.7989 0.16409 0.20885 3.1623 0.055728 0.034974 0.035186 0.006044 2.8442 0.11605 0.15777 2.3714 0.056822 0.03563 0.035816 0.0065427 2.9042 0.080319 0.11779 1.7783 0.05788 0.036231 0.036388 0.0071917 2.9735 0.062615 0.094289 1.3335 0.059116 0.036877 0.037 0.0082117 3.0651 0.049087 0.074447
VNa = T1a.Properties.VariableNames;
T1b = T1(:,[1 9:end]);
T1b.Properties.VariableNames = VN([1 9:end])
T1b = 41×8 table
Eta0 (Pa*s) Velocity magnitude (m/s) abs(u2) (m/s) abs(v2) (m/s) abs(w2) (m/s) Shear rate (1/s) Turbulent kinetic energy (m^2/s^2) Turbulent dissipation rate (m^2/s^3) ___________ ________________________ _____________ ______________ ______________ _________________ __________________________________ ____________________________________ 100 0.046152 0.028947 0.029193 0.0051372 2.6321 3.6098 2.8968 74.989 0.046738 0.029317 0.029565 0.00513 2.6357 2.8395 2.3878 56.234 0.047392 0.029729 0.029978 0.0051352 2.6416 2.2157 1.9436 42.17 0.048106 0.030177 0.030429 0.0051491 2.6495 1.7175 1.5681 31.623 0.04881 0.030619 0.030872 0.0051677 2.6586 1.3195 1.2492 23.714 0.049499 0.031053 0.031306 0.0051902 2.6689 1.0053 0.98458 17.783 0.0502 0.031494 0.031748 0.0052192 2.681 0.75994 0.7699 13.335 0.050918 0.031947 0.0322 0.0052572 2.6952 0.57022 0.59867 10 0.051743 0.032468 0.032719 0.0053134 2.7131 0.42422 0.46324 7.4989 0.052651 0.033042 0.03329 0.0053967 2.7355 0.31272 0.35701 5.6234 0.053632 0.033662 0.033903 0.0055255 2.7635 0.22807 0.27396 4.217 0.054659 0.034308 0.034538 0.0057281 2.7989 0.16409 0.20885 3.1623 0.055728 0.034974 0.035186 0.006044 2.8442 0.11605 0.15777 2.3714 0.056822 0.03563 0.035816 0.0065427 2.9042 0.080319 0.11779 1.7783 0.05788 0.036231 0.036388 0.0071917 2.9735 0.062615 0.094289 1.3335 0.059116 0.036877 0.037 0.0082117 3.0651 0.049087 0.074447
VNb = T1b.Properties.VariableNames;
figure
loglog(T1a{:,1}, T1a{:,2:end}, 'LineWidth',2)
grid
xlabel(VNa{1})
ylabel('Values')
title('T1a')
legend(VNa{2:end}, 'Location','northoutside', 'NumColumns',2)
figure
loglog(T1b{:,1}, T1b{:,2:end}, 'LineWidth',2)
grid
xlabel(VNb{1})
ylabel('Values')
title('T1b')
legend(VNb{2:end}, 'Location','northoutside', 'NumColumns',2)
Check = all(table2array(T1a) == table2array(T1b),'all')
Check = logical
1
EDIT — (26 Dec 2023 at 18:22)
Added the plots and the ‘Check’ variable, code otherwise unchanged.
The data appear to be the same in both sections of the data (denoted here as ‘T1a’ and ‘T1b’). The result of the all call (the ‘Check’ variable) verifies that they are.
.
  2 Comments
Saeid
Saeid on 5 Jan 2024
Hi Star Strider,
first of all, happy new year!
And just a quick message to inform you that I used your suggestion and it works perfectly, but at the same time, I realized that the double naming in case of the column headers was an error from my side, I have to apologize for this since I guess it made you search and find a solution. This also means I will only need the first series T1 and nothing further. For other output file formats I will then only need to change the method slightly and I guess I will be fine!
Thanks again,
Saeid
Star Strider
Star Strider on 5 Jan 2024
Happy New Year!
As always, my pleasure!
No worries about the duplication. I just needed to figure out a way to work with it, once I discovered it.

Sign in to comment.

More Answers (1)

Ganesh
Ganesh on 24 Dec 2023
Hi @Saeid,
I understand that you are trying to search for text in your ".txt" and then extract all the columns of the table contained within the ".txt" file.
Assuming that the number of headers are contact, firstly, you would need to seperate the headers from the table.
You can use the following code to extract the file into lines, and split the two files. Then the table will be created dynamically based on the fact that between two columns, there is atleast two white spaces.
InText = textscan(fileID,"%s","Delimiter","\n");
InText = InText{1}; % textscan returns a 1x1 cell array, hence extract all the lines of the file
Headers = join(InText(1:4,:)); % Using join to concatenate into one string
strfind(Headers{1},Text2Find); % Finding index of required substring, returns empty if string is not found
Tabletext = join(InText(5:end,:),"\n"); % Creating a string of the table data
Tablecsv = regexprep(Table{1}, '\s{2,}', ','); % Replacing all the column gaps with commas
Tablecells = split(split(csv_formatted_str,"\n"),","); % Splitting the rows with '\n', and the column of each row using ','
Hope this helps!

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!