Conversion to char from cell is not possible error?
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Image Analyst
2016-12-12
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 个评论
Image Analyst
2016-12-14
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.
Walter Roberson
2016-12-12
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!