How To extract a matrix from the text file?

1 回表示 (過去 30 日間)
Sultan
Sultan 2018 年 8 月 6 日
コメント済み: Sultan 2018 年 8 月 7 日
* 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
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.
Sultan
Sultan 2018 年 8 月 6 日
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.

サインインしてコメントする。

採用された回答

dpb
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);
  1 件のコメント
Sultan
Sultan 2018 年 8 月 7 日
Thanks a lot dpb!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by