How do i read the exact values from a textfile
古いコメントを表示
I have a textfile that contains a vector of length 441. However when i use the fileread command, Matlab says the file has length.12350. It prints put all the values but a wrong size. How do I correct this?
The file ia attached below
5 件のコメント
Deepak Gupta
2020 年 4 月 28 日
Include your text file.
Geoff Hayes
2020 年 4 月 28 日
SA - what happens if you use importdata instead? fileread does the same for me (creating an array of size 1x12350) because it is a character array and not the numeric array that you are expecting.
SA
2020 年 4 月 28 日
Geoff Hayes
2020 年 4 月 28 日
SA - strange..not sure why it would be empty. Possibly something in the formatting of the file (?). See Tommy's answer below for a working solution.
SA
2020 年 4 月 29 日
回答 (1 件)
fileread is reading each character from the file. If you want to interpret those characters as numbers, one option is to use textscan:
fileID = fopen('finite1_lu.txt');
A = textscan(fileID, '%f', 'HeaderLines', 1);
fclose(fileID);
8 件のコメント
SA
2020 年 4 月 28 日
Tommy
2020 年 4 月 28 日
A 441x1 double array should be stored in A{1}.
SA
2020 年 4 月 28 日
Tommy
2020 年 4 月 28 日
Have you run the code in my answer? What results did you get?
SA
2020 年 4 月 28 日
Tommy
2020 年 4 月 28 日
Hmm. Any luck with readmatrix?
A = readmatrix('finite1_lu.txt', 'NumHeaderLines', 1, 'ExpectedNumVariables', 1);
SA
2020 年 4 月 29 日
SA
2020 年 4 月 29 日
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!