How can I import a vector of vectors from txt file into a matrix
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a data.txt file that looks like this, for example:
[1,2,3,[1,2,3,4,5,6,7,8,9,10]]
[1,2,4,[2,3,4,5,6,7,8,9,10,11]]
[1,2,5,[3,4,5,6,7,8,9,10,11,12]]
the length of each line and each inner-vector, the forth element in each line, is always the same.
how can i import that data into a matrix that will contain the forth element as a vector of its own?
i have tried to import the data using 'importdata', which imported it as a (numOfLines*1) cell and using 'cell2mat' but i got that error:
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
0 件のコメント
回答 (1 件)
KSSV
2022 年 2 月 4 日
fid = fopen('data.txt') ; % your data file
S = textscan(fid,'[%f,%f,%f,[%f,%f,%f,%f,%f,%f,%f,%f,%f,%f]]');
fclose(fid) ;
S = cell2mat(S) ;
A = S(:,1:3) ;
B = S(:,4:end) ;
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!