How To extract a matrix from the text file?

1 Ansicht (letzte 30 Tage)
Sultan
Sultan am 6 Aug. 2018
Kommentiert: Sultan am 7 Aug. 2018
* end cdd+: Double Description Method in C++:Version 0.77(August 19, 2003)
* Copyright (C) 1999, Komei Fukuda
* Compiled for Floating-Point Arithmetic
*Input File:./ine/ucube.ext(15x16)
*HyperplaneOrder: LexMin
*Degeneracy preknowledge for computation: None (possible degeneracy)
*Hull computation is chosen.
*Zero tolerance = 1e-06
*Computation starts at Thu Aug 2 17:29:09 2018
* terminates at Thu Aug 2 17:29:09 2018
*Total processor time = 0 seconds
* = 0h 0m 0s
*Since hull computation is chosen, the output is a minimal inequality system
*FINAL RESULT:
*Number of Facets = 15
H-representation
begin
2 4 real
0 1 -2 1
0 -1 6 3
end
This text file started from * end cdd+:... I want to extract the following matrix:
0 1 -2 1
0 -1 6 3
The text just before and end of the matrix does not change. Please help me. Thanks in advance.
  3 Kommentare
dpb
dpb am 6 Aug. 2018
I'd bet the 2 4 real is a description header for the data between the begin...end section; 2,4 is size, real is type (albeit are integral-valued, that's akin to ML using default double for everything). With that it's pretty-much piece of cake to read as can interpret the shape and write explicit format string (or, if use the empty format string in textread after finding the location of the data section, it should automagically return the right shape as it will read 'til a conversion failure on the end.
The real question is whether the header section is fixed number of records or one has to find the data section.
Sultan
Sultan am 6 Aug. 2018
Thanks Jan and dpb! I would like to say that cdd is published by Komei Fukuda which is free available on online. I need only the matrix i.e., 2x4 matrix. "2 4 real" can be considerd as a header. I will be very thankful if you can help me.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 6 Aug. 2018
fid=fopen('yourfile');
while ~feof(fid)
l=fgetl(fid);
if ~isempty(strfind(l,'begin')), break, end
end
array=cell2mat(textscan(fid,'','headerlines',1,'collectoutput',1));
fid=fclose(fid);

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by