how to select colomns?

1 次查看(过去 30 天)
maha arcc
maha arcc 2015-10-29
评论: dpb 2015-10-29
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 个评论
dpb
dpb 2015-10-29
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...

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by