Index exceeds matrix dimensions. (loading datas)

조회 수: 2 (최근 30일)
Lee Ariana
Lee Ariana 2011년 11월 3일
Hello guys, Currently, i try to load multiple of data into MATLAB. The input.csv consists of 100 rows and 9 column integer value (positive and negative). I keep get this error for line one = strncmpi {C{10} , 'one' , 3}; Really appreciate if you guys can help me since i'm a beginner to MATLAB.
fid = fopen ('D:\MATLAB\R2010b\Japanese\input.csv');
C = textscan(fid,'%f%f%f%f%f%f%f%f%f','delimiter' , ',');
fclose(fid);
input = [C{1} C{2} C{3} C{4} C{5} C{6} C{7} C{8} C{9}];
one = strncmpi {C{10} , 'one' , 3};
two = strncmpi {C{10} , 'two' , 3};
three = strncmpi {C{10} , 'three' , 5};
four = strncmpi {C{10} , 'four' , 4};
five = strncmpi {C{10} , 'five' , 4};
six = strncmpi {C{10} , 'six' , 3};
seven = strncmpi {C{10} , 'seven' , 5};
eight = strncmpi {C{10} , 'eight' , 5};
nine = strncmpi {C{10} , 'nine' , 4};
ten = strncmpi {C{10} , 'ten' , 3};
target = double ([one two three four five six seven eight nine ten]);
input = input';
target = target';
Thank You Ariana

답변 (3개)

Bengt-Arne
Bengt-Arne 2011년 11월 3일
There is only 9 "%f%f%f%f%f%f%f%f%f" in C = textscan(fid,'%f%f%f%f%f%f%f%f%f','delimiter' , ','); fclose(fid);
Add one more %f=).
  댓글 수: 2
Lee Ariana
Lee Ariana 2011년 11월 3일
Thanks Bengt-Arne
Wasn't that '%f%f%f%f%f%f%f%f%f' represent 9 floating number in my input.csv?
i did add one more %f but the i've got another error
??? Undefined variable "strncmpi" or class "strncmpi".
Error in ==> newff at 13 one = strncmpi {C{10} , 'one' , 3};
Walter Roberson
Walter Roberson 2011년 11월 3일
strncmpi(C{10},'one',3);
Notice the use of () rather than {}

댓글을 달려면 로그인하십시오.


Fangjun Jiang
Fangjun Jiang 2011년 11월 3일
You have 9 columns of data so I assume the resulting C is a 1x9 cell array. You don't have C{10}. That is what the error message is about.
  댓글 수: 1
Lee Ariana
Lee Ariana 2011년 11월 3일
Thanks Fangjun Jiang to identify the problem.

댓글을 달려면 로그인하십시오.


Ora Zyto
Ora Zyto 2011년 11월 3일
Ariana,
If your data import worked correctly, your cell C should be a 1x9 cell array, with each cell being a 100x1 double array.
Therefore, C{10} is not defined, since this would be cell #10 of C.
Also, strncmpi is a string comparison function. What are you trying to achieve with this functionality?
Finally, if you're working with comma-separated file, you may want to use CSVREAD instead: this will get you a matrix of numbers directly, without having to deal with the cell array.
Ora
  댓글 수: 2
Lee Ariana
Lee Ariana 2011년 11월 3일
Thanks Ora Zyto,
Actually i'm develop a language translator (signal processing) by using LPC and ANN. There is no problem by using ANN toolbox but i want to try the coding method.
I want to load 100 of wave file into my MATLAB project and each row consists of 9 column of value generate by LPC function.
So now, input is 100 x 9 cell array , C is 1 x9 cell array and fid is 3.
However, i'm having problem to load the data into my MATLAB environment. I'm using MATLAB vR2010b and a beginner.
Really appreciate your help.
Thanks
Ariana
Ora Zyto
Ora Zyto 2011년 11월 4일
Ariana,
I don't understand where you are having issues. Your current workflow through:
input = [C{1} C{2} C{3} C{4} C{5} C{6} C{7} C{8} C{9}];
should generate a 100 x 9 matrix.
I was suggesting replacing all those lines (from fopen) by:
input = csvread('D:\MATLAB\R2010b\Japanese\input.csv');
If you are having other difficulties with your data, please explain exactly what the issue is.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by