How To extract a matrix from the text file?
조회 수: 3 (최근 30일)
이전 댓글 표시
* 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
dpb
2018년 8월 6일
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.
채택된 답변
dpb
2018년 8월 6일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!