Unknown Error

EDU>> fid = csvread(uigetfile({'*.csv';'*.txt';'*.dat'}, 'Select the CV File'), 2, 1, 'eof');
??? Attempted to access range(3); index out of bounds because numel(range)=0.
Error in ==> dlmread at 108
if r > range(3) || c > range(4), result= []; return, end
Error in ==> csvread at 54
m=dlmread(filename, ',', r, c, rng);
The top is the line I am trying to execute and the bottom is the subsequent error message I am receiving. I have tried trouble shooting it myself but I am not sure what the problem is. Can anyone help?

Answers (5)

Richard Brown
Richard Brown on 23 Apr 2012

0 votes

The fourth argument to csvread should be a range, i.e. a vector with four entries. You have 'eof'. Try removing this argument and see if this fixes your problem.

1 Comment

Lukas
Lukas on 23 Apr 2012
EDU>> fid = csvread(uigetfile({'*.csv';'*.txt';'*.dat'}, 'Select the CV File'), 2, 1);
??? Error using ==> textscan
Mismatch between file and format string.
Trouble reading number from file (row 1, field 2) ==> C-V S
Error in ==> csvread at 52
m=dlmread(filename, ',', r, c);
That is the response I get. :(

Sign in to comment.

Walter Roberson
Walter Roberson on 23 Apr 2012

0 votes

csvread() cannot be used for files that have text headers. Not even when you specify the row and column.
If you have text headers, use textscan() directly.

4 Comments

Lukas
Lukas on 23 Apr 2012
So the reason why I was trying cvsread is because I still am unclear as to how textscan works. Its output is a cell array correct? Do I have to use fopen to use textscan because I was getting errors associated with fopen (I believe anyway). If I can get it to work, I should be able to search within the cell array for at least partial matches for strings to identify a specific line correct? How can I specify a string and the have the remaining portion of the string to the end of the line be saved as a separate array/matrix?
Walter Roberson
Walter Roberson on 24 Apr 2012
For the case of a file that is numeric except for header lines:
numheader = 1; %adjust to the actual number of headers
numcol = 7; %adjust to the actual number of columns
thisfmt = repmat('%f', 1, numcol);
fid = fopen('CV US Protocol_BD1726-54 1000ud1.csv', 'rt');
C = textscan(fid, thisfmt, 'Delimiter', ',', 'HeaderLines', numheader);
fclose(fid);
If this is not what your file looks like, then a sample of your file would help.
Lukas
Lukas on 27 Apr 2012
The response I get when I load the code
fid = fopen(uigetfile({'*.csv';'*.txt';'*.dat'}, 'Select the CV File'), 'rt');
Just in the command window I get fid=-1 meaning that it couldnt open the file correct?
Lukas
Lukas on 27 Apr 2012
...one add on to that, I get that response obviously after I have selected the file.

Sign in to comment.

Lukas
Lukas on 24 Apr 2012
I also have tried using fopen directly
EDU>> fid = fopen('CV US Protocol_BD1726-54 1000ud1.csv')
fid =
3
EDU>> C = textscan(fid, 'r')
C =
Empty cell array: 1-by-0
To try and put the data into a cell array but as you can see, for some reason, the cell array is emtpy. Can anyone help me figure this out? Thanks
Lukas
Lukas on 24 Apr 2012
SetupTitle, CV US Protocol
PrimitiveTest, C-V Sweep
TestParameter, Channel.UnitTyp, CMU
TestParameter, Channel.Unit, CMU1:MF/SC
TestParameter, Channel.IName,
TestParameter, Channel.VName, VBias
TestParameter, Channel.Mode,
TestParameter, Channel.Func, VAR1
TestParameter, Channel.Index,
TestParameter, Channel.Time,
TestParameter, Measurement.Primary.Locus, Single
TestParameter, Measurement.Primary.Scale, LINEAR
TestParameter, Measurement.Primary.Start, -10
TestParameter, Measurement.Primary.Stop, 10
TestParameter, Measurement.Primary.Step, 0.1
TestParameter, Measurement.Aborting.Condition, CONTINUE AT ANY
TestParameter, Measurement.PostOutput.Value, START
TestParameter, Measurement.PostOutput.Retention, OFF
TestParameter, Measurement.Secondary.ACLevel, 0.03
TestParameter, Measurement.Secondary.FName, Freq
TestParameter, Measurement.Secondary.Frequency, 1000000, 100000, 10000, 1000
TestParameter, Measurement.Bias.Source, 0
TestParameter, Measurement.ImpedanceMode.Model, Cp-G
TestParameter, Measurement.ImpedanceMode.CName, C
*....... I cut out the whole header just to give you a portion of it but it is 200+ lines if strings (obviously asymmetric in columns) *
AnalysisSetup, Analysis.Setup.Vector.List.Datum.Name, VBias, C, G
AnalysisSetup, Analysis.Setup.Vector.List.Datum.Unit, V, F, S
AnalysisSetup, Analysis.Setup.Preference.GraphVisible, true
AnalysisSetup, Analysis.Setup.Preference.ListVisible, true
AnalysisSetup, Analysis.Setup.Preference.ScalarVisible, true
AnalysisSetup, Analysis.Setup.Title, CV US Protocol
Dimension1, 201, 201, 201
Dimension2, 4, 4, 4
DataName, VBias, C, G
DataValue, -10, 7.14698E-11, 7.31843E-06
DataValue, -9.9, 7.2232999999999992E-11, 3.75349E-06
DataValue, -9.8, 7.26777E-11, 5.50536E-06
DataValue, -9.7000000000000011, 7.28037E-11, 4.36322E-06
DataValue, -9.6, 7.33505E-11, 4.8255199999999995E-06
DataValue, -9.5, 7.37495E-11, 2.7934899999999997E-06
DataValue, -9.4, 7.36746E-11, 7.22263E-06
DataValue, -9.3, 7.46931E-11, 6.51808E-06
Anyway, there is a blank space line at the start that is not shown. I am interested in the frequencies listed on line 21 and then obviously the data on line listing 'DataValue'
Any help would be greatly appreciated. :)
Image Analyst
Image Analyst on 27 Apr 2012
csvread expects a bunch of numbers, not mixed numbers and text, and different numbers of things on each line, like you have:
AnalysisSetup, Analysis.Setup.Title, CV US Protocol
Dimension1, 201, 201, 201
Dimension2, 4, 4, 4
DataName, VBias, C, G
DataValue, -10, 7.14698E-11, 7.31843E-06
Since each line is so vastly different, you might have to read each line with fgetl() or fgets() and parse each line depending on what it looks like.

3 Comments

Lukas
Lukas on 27 Apr 2012
Its not possible to treat each line as a string and input into a cell array?
Image Analyst
Image Analyst on 27 Apr 2012
You can do that if you want. Read each line in one at a time like I said, parse it into things between the commas (you can use allwords for that http://www.mathworks.com/matlabcentral/fileexchange/27184-allwords) and then put those sentence fragments into cells.
Lukas
Lukas on 4 May 2012
Thanks, I will give it a try

Sign in to comment.

Categories

Asked:

on 23 Apr 2012

Community Treasure Hunt

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

Start Hunting!