Regarding textscan error - Values must be increasing and non-NaN

Hi, I am trying to read a text file using "textscan"
[B, spc] = textscan('A.txt','%f %f');
This file has two columns of numbers separated by a space (with no header), which I want to fit to a polynomial later on. First column has ever increasing positive numbers while second column has both positive and negative numbers. I am repeatedly getting the following error message -
Error using set
Bad property value found.
Object Name : axes
Property Name : 'XLim'
Values must be increasing and non-NaN.
Seems there is something wrong in my textfile. Would appreciate any help in this regard. Thanks. SG

 Accepted Answer

fid=fopen('A.txt')
b= textscan(fid,'%f %f');
fclose(fid)
out=cell2mat(b)

More Answers (1)

[B, spc] = textscan('A.txt','%f %f');
says that the string 'A.txt' should be examined to find two floating point values. As 'A.txt' is not a string that starts with a floating point number, no values will be matched, so the cell array with two empty columns (because two format strings) will be returned into B. The count of the number of characters used will be returned into spc, and since no characters of the string 'A.txt' were used, that value is going to be 0.
Are you possibly thinking of textread() ?

3 Comments

Dear, Thanks for your answer. Actually I started with textread, but then it was showing some error and so I decided to try textscan. After your suggestion, I tried textread again and it worked. Thanks once again.
@sg_matlab, it seems that you misunderstood Walter's comment. The way you were using textscan doesn't allow to read the content of the file A.txt, but reads the content of the string 'A.txt', which is: { 'A' '.' 't' 'x' 't' }
Azzi: yes, but the syntax that they used was really the textread syntax,
[B, spc] = textread('A.txt', '%f f');
so they can use that to read the file and make assignments of the columns to the variables.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!