MATLAB: Doesn’t this matlab code work?!

cellerror

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)=[]

Best Answer

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: