Why doesn't this matlab code work?!

조회 수: 1 (최근 30일)
Ahmad
Ahmad 2015년 1월 3일
댓글: Image Analyst 2015년 1월 3일
s={'CCCAGCTCCCGAATTCCCCAGCTA'};
rec={'AG^CT'};
x=strfind(rec,'^');
y=rec;
y(x)=[]
I get:
Error using subsindex Function 'subsindex' is not defined for values of class 'cell'.
Error in Untitled555555 (line 5) y(x)=[]

채택된 답변

Stephen23
Stephen23 2015년 1월 3일
편집: Stephen23 2015년 1월 3일
Because x is a cell array, and you are trying to use this to index into the variable y, which is not supported in MATLAB (indices must be numeric or logical). If you have a look in your workspace you will find that all of your variables are in fact cell arrays... is this intentional? Depending on your application it may be unnecessary to use cell arrays at all:
s = 'CCCAGCTCCCGAATTCCCCAGCTA';
rec = 'AG^CT';
x = strfind(rec,'^');
y = rec;
y(x)=[];
using no cell arrays, and works without error. If you think you really do need to use cell arrays, please post more details of what you are trying to achieve and we can help you further with the best way to code it using MATLAB.
These might be of interest:

추가 답변 (3개)

Image Analyst
Image Analyst 2015년 1월 3일
then try this:
rec={'AG^CT'};
x=strfind(char(rec),'^')
y=rec
y{1}(x)=[]

Ahmad
Ahmad 2015년 1월 3일
couldn't understand what it says, plus i'm trying to add this line too, can u fix it:
cut_position= strfind(s,y) + x -2;
it's giving me this error: Error using cell/strfind (line 32) If any of the input arguments are cell arrays, the first must be a cell array of strings and the second must be a character array.
Error in Untitled555555 (line 6) cutpos= strfind(s,{y}) + x -2;
  댓글 수: 1
Image Analyst
Image Analyst 2015년 1월 3일
Your error doesn't match your code. In the strfind, do you have y or {y} ? And if it's {y}, then why???
Say, did you ever look at the FAQ link I gave you? Please do. I gave it to you because I think it will help you understand cell arrays. If you can't understand the FAQ, let me know and I'll clarify it.

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


Ahmad
Ahmad 2015년 1월 3일
thank u so much for offering help, i understand what a cell array is now, but i don't understand thsis syntax "y{1}", and sorry i was trying different things so the rror was for a previous code, but now i get this error:
Undefined function 'plus' for input arguments of type 'cell'.
Error in Untitled555555 (line 6) cut_position= strfind(s,y{1}) + x -2;
  댓글 수: 1
Image Analyst
Image Analyst 2015년 1월 3일
Not sure you do understand cells yet because you'd know that y{1} means "contents of the first cell of y". So y is a cell or a cell array (a columns or row vectors). Then 1 means take the first cell in the row, or first cell in the column, and get the contents of it, which could be virtually anything - a string, a structure, a double, an image, even another cell. In your case y is a cell array where the cells contain strings, so y{1} is a string.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by