how to select colomns?
1 view (last 30 days)
Show older comments
I try to run an .m-file to make state estimation of power system using WLS criteria. I entered chi-squared table to my .mfile using the following commands:
fid = fopen('chi_2.txt');
tline = fgetl(fid);
while ischar(tline)
disp(tline);
tline = fgetl(fid);
end
and it works. after that i tried to select only two columns, the first one (Degree of freedom) and the column (11) (the value of chi) and enter them through loop to reject bad readings one at a time.
The value of the Degree of freedom (DOF) decreases one at a time so the value of chi is also changed.
when i tried to select the columns using the :
sub_chi=tline(10:20,11:12)
I got the following message:Index exceeds matrix dimensions.
Index exceeds matrix dimensions.
Error in wls (line 292)
sub_chi=tline(10:20,11:12)
could you please help me to overcome this problem
1 Comment
dpb
on 29 Oct 2015
tline = fgetl(fid);
returns only the single line of data in the file as a character string; not any values represented by those numeric characters converted to numeric values. The expression
sub_chi=tline(10:20,11:12)
is a 2D indexing expression, hence the "out of bounds" error for the second expression which is interpreted as asking for lines 11 and 12 of a one-line expression.
To read these two values you need to use sscanf or textscan based on the format of the file but reading line-by-line and parsing those lines is the most difficult way to try to read a file...
Show a few lines of the file for guidance in needed, but consult
doc importdata
doc textscan
and other i/o functions to see which may fit your data file most closely. Or use the interactive import tool...
Answers (0)
See Also
Categories
Find more on Large Files and Big Data 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!