How To extract a matrix from the text file?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
* 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
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.
Akzeptierte Antwort
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)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!