How can I get the text instead of NaN when using import options for readtable?

5 visualizaciones (últimos 30 días)
Dear all,
I'm using readtable to import data from an open inventor file. The file has some delimited text and point cloud data as x,y,z coordinates that I need.
The file for example looks like this:
My code so far only separates all coordinates from the open inventor file.
To separate them I use readtable with following import options:
But now I want to:
  1. Import the open inventor file as a table (like I do already)
  2. Find a range that can be defined by a first/last row with a specified text
  3. Remove all NaN rows in this range to separate the coordinates
  4. Use finally a n-rows by 3-columns table to continue processing
My problem now:
If I convert the file to a table with the import options from above, I cannot search for the range boundaries I need, because every text element is converted to NaN. How can I get back the original text and search for the specified rows including text?
attached is a text file that is identical to the open inventor file. If you try to reproduce my code, please rename the extention to ".iv" to reproduce the same behaviour.
I'm using Matlab 2020b.
Thank you very much in advance!
  3 comentarios
Florian Teriet
Florian Teriet el 27 de Nov. de 2020
Dear dpb,
thank you for your fast reply! Using fgetl is in my opinion to slowly for reading. I Solved it by calling readtable two times with different input options.
With Opts1 I get the whole line in one cell and then search for the target range by text.
With Opts2 I use my previous code, take my target range from Opts1 and delete all NaNs.
This is what I needed in this case.
If someone has a better idea do not hesitate and comment too. Thanks :)
Opts1 = detectImportOptions(DirectPath,'FileType','text','NumHeaderLines',0,'ExpectedNumVariables',3,'VariableNamingRule','preserve');
FileTable1 = readtable(DirectPath,Opts1);
FileArray1 = table2array(FileTable1);
StartIndex = find(ismember(FileArray1,StartText),1,'last');
EndIndex = find(ismember(FileArray1,EndText),1,'last');
Opts2 = detectImportOptions(DirectPath,'FileType','text','Delimiter',{',',' '},'PreserveVariableNames',true,'ExpectedNumVariables',3,'Range','A:C');%
FileTable12 = readtable(DirectPath,Opts2);
FileArray2 = table2array(FileTable12);
FileArray2(EndIndex:end,:,:)= [];
FileArray2(1:StartIndex,:,:)= [];
FileArray2 = rmmissing(FileArray2);
dpb
dpb el 16 de Dic. de 2020
I suspect you'd be surprised at relative timing between fgetl and calling detectImportOptions, readtable and table2array twice

Iniciar sesión para comentar.

Respuestas (1)

Prashik Shende
Prashik Shende el 16 de Dic. de 2020

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by