when the secret text contain pair(doubke) character like 'dd',mm' ,'ll', the Y vector reswtores as Nan

hello all; i have one problem in this code which is , when the secret text contain pair(double) character like 'dd',mm','oo', the Z vector restore as NaN, how i can solve this problem.
str='steganography is the art and science of covered or hidden';
X={'as modeling of changes in backbone conformation still lacks a computationally efficient solution, we developed a discretisation of the conformational states accessible to the protein backbone similar to the successful rotamer approach in side chains. The BriX fragment database, consisting of fragments from 4 to 14 residues long, was realized through identification of recurrent backbone fragments from a non-redundant set of high-resolution protein structures. brix contains an alphabet of more than 1,000 frequently observed conformations per peptide length for 6 different variation levels. analysis of the performance of brix revealed an average structural coverage of protein structures of more than 99 percent within a root mean square distance of 1 angstrom. globally, we are able to reconstruct protein structures with an average accuracy of 0.48 angstrom rmsd. as expected, regular structures are well covered, but, interestingly, many loop regions that appear irregular at first glance are also found to form a recurrent structural motif, albeit with lower frequency of occurrence than regular secondary structures. larger loop regions could be completely reconstructed from smaller recurrent elements, between 4 and 8 residues long. finally, we observed that a significant amount of short sequences tend to display strong structural ambiguity between alpha helix and extended conformations. when the sequence length increases, this so-called sequence plasticity is no longer observed, illustrating the context dependency of polypeptide structures.'};
for m = 1:numel(X)
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & cumsum(Y(:,n-1))>0;
end
Z = find(any(diff([false(size(str));cumsum(Y)>0],1),2))
end

 Accepted Answer

I think you just need to preallocate the cell array, and then index into it inside the loop:
str = 'steganography is the art and science of covered or hidden';
X = {'as modeling of changes in backbone conformation still lacks a computationally efficient solution, we developed a discretisation of the conformational states accessible to the protein backbone similar to the successful rotamer approach in side chains. The BriX fragment database, consisting of fragments from 4 to 14 residues long, was realized through identification of recurrent backbone fragments from a non-redundant set of high-resolution protein structures. brix contains an alphabet of more than 1,000 frequently observed conformations per peptide length for 6 different variation levels. analysis of the performance of brix revealed an average structural coverage of protein structures of more than 99 percent within a root mean square distance of 1 angstrom. globally, we are able to reconstruct protein structures with an average accuracy of 0.48 angstrom rmsd. as expected, regular structures are well covered, but, interestingly, many loop regions that appear irregular at first glance are also found to form a recurrent structural motif, albeit with lower frequency of occurrence than regular secondary structures. larger loop regions could be completely reconstructed from smaller recurrent elements, between 4 and 8 residues long. finally, we observed that a significant amount of short sequences tend to display strong structural ambiguity between alpha helix and extended conformations. when the sequence length increases, this so-called sequence plasticity is no longer observed, illustrating the context dependency of polypeptide structures.'};
Z = cell(size(X));
for m = 1:numel(X)
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & cumsum(Y(:,n-1))>0;
end
Z{m} = find(any(diff([false(size(str));cumsum(Y)>0],1),2));
end
EDIT: improved code that takes into account repeated characters (see the comments):
m = 1;
str = 'communication';
X = {'computers memory unites collection demarcation'};
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & [false;cumsum(Y(1:end-1,n-1))>0];
end
find(any(Y & cumsum(Y)<2, 2))

6 Comments

there is no difference according to previous code, they give me same result.
Can you please explain exactly what the problem is, with actual examples and indices. It is not clear what you need.
thank you Stephan; brother my objective is to find str's letters from X. in additional,when i get one of the characters of str, the loop will be continue the search from that position and will not start again from 1, till str's length ends. suppose i have:
str='communication';
X={'computers memory unites collection demarcation'};
if we apply to the current code the fourth element of str 'm' is missing from the output of the code that is my problem and i think if the previous letter same to next letter the code will ignore the current one and jumping to the next one:
1
2
3
5
19
20
25
39
43
44
45
46
NaN
while the estimated output is:
1
2
3
11
18
19
20
25
39
43
44
45
46
additionally i executed this code:
str='communication';
X={'computers memory unites collection demarcation'};
Z = nan(size(X,1),numel(str));
for m = 1:numel(X)
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & cumsum(Y(:,n-1))>0;
end
tmp = find(any(diff([false(size(str));cumsum(Y)>0],1),2));
Z(m,1:numel(tmp)) = tmp;
end
hello all, is there some who can help me the solution of this error, i am waiting more suitable answer till yesterday. thank you
You are right, there was a bug in my original concept in that it did not take into account repeated characters. This version is more robust, and gives the output that you need:
m = 1;
str = 'communication';
X = {'computers memory unites collection demarcation'};
Y = bsxfun(@eq,X{m}(:),str);
for n = 2:size(Y,2)
Y(:,n) = Y(:,n) & [false;cumsum(Y(1:end-1,n-1))>0];
end
find(any(Y & cumsum(Y)<2, 2))
And it displays this in the command window:
ans =
1
2
3
11
18
19
20
25
39
43
44
45
46

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!