필터 지우기
필터 지우기

Saving the content of a cell array into a file

조회 수: 3 (최근 30일)
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 11일
편집: per isakson 2017년 11월 12일
I want to write a content of a cell array into an m-file. I copied the content of a function file and save it in a cell array so as to make some modifications and then save it back into another function file. I would then pass the same input to the two separate functions (original and modified). I have a number of the modified functions called msize. If the result of the original function is different from the modified, ONE is assigned to the output array that compares the result otherwise ZERO is assigned. The code is returning only ONEs or ZEROs. But when I executed the code step-wise, it's returning correct results. I don't know perhaps the writing I made to the new function file does not allow writing of other files so that the first result is often repeated. See the code below:
function [killVector] = Tester(fname,mutants,tcase)
%%An edited version of an original function is called its mutant.
% Test cases are generated and passed as "tcase" in this function while
% fname is the name of the function to be passed, mutants is the cell
% array of the mutants. The same test cases are passed to the original
% and each of its mutants. If the result of the original version is
% different from the mutant's, then the mutant is killed else alive. The
% killVector stores the vector of killing of each mutant. If the mutant is
% killed, its killing value is ONE but if it's alive, the value is ZERO
num = numel(de2bi(numOfLines(fname)));
msize=length(mutants);
a=bin2dec(num2str(tcase(1)))+1;
b=bin2dec(num2str(tcase(2:5)))+1;
c=bin2dec(num2str(tcase(6:end)))+1;
%
%disp(realResult);
nfname='mutantfname.m';
T=zeros(msize,1);
values=zeros(msize,1);
i = 1;
while(i <= msize/3)
%for i=1:msize
chr=mutants{i};
op=bin2dec(num2str(chr(1)))+1;
lnum=round(bin2dec(num2str(chr(2:num+1)))+1);
choice=round(bin2dec(num2str(chr(num+2:end)))+1);
if (op==1)
mutated=arithRep(fname,lnum,choice);
elseif (op==2)
mutated=relRep(fname,lnum,choice);
end
writeToFile(nfname,mutated);
% filenames=strcat('m',num2str(i),'.m');
% writeToFile(filenames,mutated);
mresult=mutantfname(a,b,c);
% delete('mutantfname.m');
% clear mutated;
values(i)=mresult;
r=randi(1);
realResult=sumOfRoots(a,b,c);% Try to shift it inside the loop after write
if isequal(realResult,mresult)
y=0;
else
y=1;
end
T(i)=y;
i = i + 1;
end
%killVector=T';
killVector=values';
end
  댓글 수: 5
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 11일
Files are here
Hayatullahi Adeyemo
Hayatullahi Adeyemo 2017년 11월 11일
Sorry, you can find it attached now

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by