Regarding textscan error - Values must be increasing and non-NaN
1 view (last 30 days)
Show older comments
sg_matlab
on 8 Apr 2016
Commented: Walter Roberson
on 8 Apr 2016
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
0 Comments
Accepted Answer
Azzi Abdelmalek
on 8 Apr 2016
fid=fopen('A.txt')
b= textscan(fid,'%f %f');
fclose(fid)
out=cell2mat(b)
0 Comments
More Answers (1)
Walter Roberson
on 8 Apr 2016
[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
Azzi Abdelmalek
on 8 Apr 2016
Edited: Azzi Abdelmalek
on 8 Apr 2016
@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' }
Walter Roberson
on 8 Apr 2016
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.
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!