Sort data from text file into columns

5 ビュー (過去 30 日間)
tg295
tg295 2018 年 7 月 20 日
コメント済み: tg295 2018 年 7 月 20 日
I have data in a text file of the form:
30.693
43.803
30.305
43.424
30.066
43.213
30.305
43.001
30.523
42.79
33.111
33.316
40.293
33.323
33.502
40.289
33.528
40.413
...
...
I would like matlab to read it into a matrix whereby each block of numbers separated by spaces above and below is made into a separate column where the first block of n numbers makes the first column and the second block of m numbers makes the second column etc, i.e.:
30.693 30.305 ... 33.323 33.528 33.737
43.803 43.424 ... 33.502 40.413 40.62
40.289
Many thanks, I am a beginner so bear with me :)
FYI I have a large number of these text files, all with different size blocks/values within each column, therefore I need a general solution not one for this specific case.

採用された回答

Christopher Wallace
Christopher Wallace 2018 年 7 月 20 日
fid = fopen('yourTxt.txt');
A = [];
tline = fgetl(fid);
ii = 1;
jj = 1;
while ischar(tline)
while ~isempty(tline)
A(ii,jj) = str2num(tline);
ii = ii + 1;
disp(tline)
tline = fgetl(fid);
end
ii = 1;
jj = jj + 1;
tline = fgetl(fid);
end
fclose(fid);
  1 件のコメント
tg295
tg295 2018 年 7 月 20 日
It worked! thanks so much :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by