MATLAB Answers

How To extract a matrix from the text file?

22 ビュー (過去 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 件のコメント

Jan
Jan 2018 年 8 月 6 日
Are you sure that Komei Fukuda wants the email address to be published?
Which parts are variable in this problem? Does "2 4 real" matter or are all arrays 2x4 matrices?
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.

サインイン to comment.

採用された回答

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!

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。


Translated by