read data from file to two-dimensional array

11 ビュー (過去 30 日間)
Ivan Volodin
Ivan Volodin 2017 年 5 月 27 日
コメント済み: Andrei Bobrov 2017 年 5 月 27 日
Hello!
There is a file, where 50x50 values are written, all in all 2500 values. They are written like this:
1
2
3
4
5
...
...
2499
2500
Therefore one value is in every string How to read data from this txt-file in Array A of dimension 25x25, so the first 25 values was the first row of the array, the second 25 second, and so on until the end?
Tried this:
fileI = fopen('file.txt','r');
formatSpec = '%f';
sizeA = [50 50];
Vx = fscanf(fileI,formatSpec,sizeA);
fclose(fileI);
Vx=Vx';
But it does not work, the whole array fills with zero.
Thanks in advance!

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 5 月 27 日
fileI = fopen('file.txt','r');
Vx = fscanf(fileI,'%f');
fclose(fileI);
out = reshape(Vx,50,[]);
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2017 年 5 月 27 日
comment by Ivan Volodin :
'Thank you!'

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by