How do i extract these arrays from a .m file?
6 ビュー (過去 30 日間)
古いコメントを表示
I need to get the matrices but I'm unsure how to proceed. The file in question is attached as a picture.
Thanks!
0 件のコメント
回答 (1 件)
Ameer Hamza
2018 年 4 月 26 日
You didn't specify the number of matrices. If it is small, the easiest way is to do it manually like this,
A = [1 0 0;
2 0.5 0;
3 1 0;
.....;
.....];
Similar for other matrices.
2 件のコメント
Ameer Hamza
2018 年 4 月 26 日
If your file is formatted as above (i.e. matrices are separated by an empty line, try following code
fID = fopen('temp_.m', 'r');
fileData = fread(fID);
fclose(fID);
fileStr = char(fileData');
%%searching for empty line (i.e. 2 new lines)
partitionIndex = strfind(fileStr, [newline newline]);
A = str2num(fileStr(1:partitionIndex(1)-1));
B = str2num(fileStr(partitionIndex(1)+2:partitionIndex(2)-1));
C = str2num(fileStr(partitionIndex(2)+2:end));
参考
カテゴリ
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!