필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Given a table, how can I find corresponding values for a given element?

조회 수: 1 (최근 30일)
S
S 2014년 11월 26일
마감: MATLAB Answer Bot 2021년 8월 20일
In this problem, you will write a function
site=getsite(enzyme,rebasefile)
that takes a restriction enzyme name and returns its recognition site, as identified from a file containing information about restriction enzymes. If a rebase file is not provided, use 'rebase_small.txt'. Download and use the example rebase file available from http://sacan.biomed.drexel.edu/ftp/bmes201/final.20131/rebase_small.txt The format of the rebase file is self-descriptive.
It must be in this format:
>> disp( getsite ('AaaI','rebase_small.txt') )
C^GGCCG
>> disp( getsite ('AamI','rebase_small.txt') )
?
>> disp( getsite ('AbaUI') )
C(11/9)
Here is what I have so far:
function out = getsite(enzyme, rebasefile)
fid=fopen('rebase_small.txt','r');
if fid<0
fprintf('I am unable to open text file.');
out=[];
end
if ~feof(fid)
line=fgetl(fid);
if strncmp(line,'enzyme',6) > 0
location=line(14:16);
location(location==' ')=[];
strncmp(location,'enzyme',6);
out = line{7};
end
end
fclose(fid);

답변 (1개)

Geoff Hayes
Geoff Hayes 2014년 11월 27일
S - you may want to consider using strfind instead of strcmp as the former will search/match on a substring rather than do a direct comparison, which I think us what you want given the Data in your file.
Note the code
if strcmp(line,'enzyme',6) > 0
I am not sure what your intent is with the 6 (does thus line of code actually work or does it throw an error?). And wrapping the enzyme input in single quotes means that this line of code (if we are to ignore the 6) will try to compare the word enzyme with the line string. Instead consider
if strfind(line,enzyme) > 0
which will try to match the variable enzyme (whatever string that may be) to a substring within the variable line.
Once you have found a match, then I suspect you want to skip a couple of lines until you reach the recognition site and save that result to an your output cell array.
Since this is a homework question, try incorporating these changes into your code.
  댓글 수: 2
S
S 2014년 11월 27일
I tried this and it is still coming as an error. The error is saying that the output argument is not assigned. What does this mean and how could I fix it?
Geoff Hayes
Geoff Hayes 2014년 11월 27일
If your code is the same as the above (with only minor changes for strfind), then it seems to be only checking the first line in the file. And if the first line does not have the enzyme you are looking for, then the code ends without assigning anything to the output parameter out.
I think that you would need to use a while loop to iterate over each line until you find the matching enzyme, then skip the next couple of lines until you reach the recognition site and assign that to out.
Note that to avoid this error, in the event that no line in the file contains the desired enzyme, you should default out to an empty string before opening the file.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by