How do i read the exact values from a textfile

조회 수: 2 (최근 30일)
SA
SA 2020년 4월 28일
댓글: SA 2020년 4월 29일
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
Geoff Hayes
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
SA 2020년 4월 29일
Hi Geoff, I used the importdata and it worked. I am just wondering why it didn't at first. Thanks for the help

댓글을 달려면 로그인하십시오.

답변 (1개)

Tommy
Tommy 2020년 4월 28일
편집: Tommy 2020년 4월 28일
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
SA 2020년 4월 29일
It says the readmatrix is an undefined name
SA
SA 2020년 4월 29일
I was able to solve it. I used the importdata and it worked. Thanks for the assistance

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by