Conversion to char from cell is not possible error?

14 views (last 30 days)
Hi, i keep getting this error message for this bit of code and i dont really understand where I'm going wrong, as a little background DNA_H is a protein sequence for a gene and Prot_M_cell is a cell array of another protein sequence where it has been split up into groups of two. The issue is the R(H)={Z} where I'm trying to store the results of the for loops in a metrix but it isnt working?
R='';
S=1000;
N_R=floor(length(R/n));
Z=0;
for H=1:S
L=randperm(length(DNA_H));
K=1:length(DNA_H);
M=L(K);
Q=DNA_H(M);
R=strcat(R,Q);
for X=1:N_R
Split_R(X,:) = R(A:A+(n-1))
Split_R_cell= cellstr(Split_R)
for XX=1:length(Split_R_cell);
if any(strcmp(Split_R_cell(XX),Prot_M_cell))
Z=Z+1;
;
end
end
end
R(H)={Z}
end

Answers (2)

Image Analyst
Image Analyst on 12 Dec 2016
Z is an integer (actually a double that takes on integer values). R is most likely a string. So you're trying to assign a cell, with Z inside the cell, to element number H (whatever H is) of string R. R is a string (character array) so you can only put characters into it, not cells. You'd have to convert Z to a character string, not a cell, then assign it.
R(H) = num2str(Z);
and if Z is not a single digit 1-9, then H had better be an array specifying enough elements to take Z. For example if Z=10, then you need two elements like R(13:14) = num2str(Z).
  2 Comments
Toby  Pendlebury
Toby Pendlebury on 13 Dec 2016
Essentially what I'm trying to do is randomise the protein sequence DNA_H 1000 times and each randomisation split it into groups of 2 and store it as a cell array, which i have previously done for Prot_M_cell. and then want to compare the sequence new randomised sequence with Prot_M_cell and store the result in a matrix, but I'm not sure why it isnt working?
Image Analyst
Image Analyst on 14 Dec 2016
You have to decide if you want to work with cell arrays or character arrays. If the things you care about are all only one single character long, then you should just use a character array and append that character on. Cell arrays are used when you want non-rectangular arrays of strings. So if your Z is always 9 or less, use character arrays. If Z can get to be 10 or more, you could use cell arrays or character arrays but you need to be a little careful about how you tack on the new number.

Sign in to comment.


Walter Roberson
Walter Roberson on 12 Dec 2016
R=''; creates R as a string. R=strcat(R,Q); makes the string longer, as a string. R(H)={Z} tries to store a cell array into a particular character position in the string.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!