Not sure what I'm doing wrong. FOR LOOP
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
This is my code for a problem that must identify the start and end position of a genome.
% fid = fopen('sequence_short.txt','r'); %Opens the file for reading
new = fopen('report_short_codon.txt','w+'); %Opens the new file for writing
fprintf(new,'Name: Derryn Scott \n'); %Prints name, date, lab title
fprintf(new,'Date: March 28, 2013 \n');
fprintf(new,'Lab 10: DNA Pattern Matching\n');
C = textscan(fid,'%1s');
codons = C{1};
for t = 1:1:63 %Steps through each value
if strcmp('T' , codons{t});
if strcmp('A' , codons{t+1});
if strcmp('C' , codons{t+2})
StartCodon = t;
break
end
end
end
end
for t = StartCodon:1:63
if strcmp('A' , codons{t});
if strcmp('T' , codons{t+1});
if strcmp('T' , codons{t+2});
elseif strcmp('C' , codons{t+2});
EndCodon = t;
break
end
end
end
if strcmp('A' , codons{t});
if strcmp('C' , codons{t+1});
if strcmp('T' , codons{t+2});
EndCodon = t;
end
end
end
end
if fid == -1 %Prints an error if needed
error('The file has failed to open')
end
%Prints everything in the new file
fprintf(new,'Start Position is : %0.0d',StartCodon);
fprintf(new,'End Position is : %0.0d',EndCodon);
fclose(fid);
fclose(new);
I keep getting this error:
Respuestas (1)
Cedric
el 3 de Abr. de 2013
Editada: Cedric
el 3 de Abr. de 2013
Difficult to know without seeing your sequence, but imagine that the cell array codons contains 60 characters.. when t = 60, addressing the element t+1 generates the error that you get. Also, realize that this code will crash if the start codon is not found.
You should display t for debugging, and also length(codons).
Now about the overall approach: you could read the file using FILEREAD and you would get an array of characters instead of this "complicated cell array". Then you could use STRFIND to identify positions of the codons that you want to match.
Another approach could be based on REGEXP for pattern matching.
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!