cvhtml help

조회 수: 6 (최근 30일)
Lucas
Lucas 2012년 6월 6일
댓글: Walter Roberson 2020년 2월 21일
Hello. I’m having a little issue with getting my coverage data to display to an html document correctly. We dynamically write an m file and we generate an mfile that has this code below:
open_system(modelname);
cvt1 = cvtest(modelname);
cvt1.setupCmd = 'load(''Util_Hydraulics31.mat'');';
cvd1 = cvsim(cvt1);
cvt2 = cvtest(modelname);
cvt2.setupCmd = 'load(''Util_Hydraulics32.mat'');';
cvd2 = cvsim(cvt2);
cvhtml('TestCoverageHTML.html', cvd1, cvd2);
cvexit();
The mfile changes based on how many test cases we have, so cvhtml could have 100 parameters passed into it this way. If I copy and paste the code into the end of our main file everything works perfectly, but if I place that into a function, in its own mfile, and call it at the end of the main file its always 1 behind. Like it I were to add 7 more cases (cvd3, cvd4, …) into cvhtml, the first time I’d run it I’d have a report with 2 test cases in it. Then if you’d run it again it’d have all 9 test cases in the report.
If you try and debug it, where we call it as a function, it works perfectly. It just went you run it like that without a breakpoint it always runs 1 behind. If you copy and paste the code into the main file and hard code everything that way it works perfectly. Any idea why this is happening? I can’t debug it because it works if you do. Thanks

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 6일
If you are dynamically creating a function file, then after each time you change it, use "clear" on the function name. MATLAB's Just In Time parser is remembering the previous version and does not check for changes to it; the clear forces it to get rid of the remembered version.
  댓글 수: 2
Tonmoy Roy
Tonmoy Roy 2020년 2월 19일
Hi Walter, I am not sure what you meant by use "clear" on the function name. Can you explain further?
Walter Roberson
Walter Roberson 2020년 2월 21일
funname = 'testit';
filename = [funname '.m'];
fid = fopen(filename, 'wt'); %create testit.m
fprintf(fid, 'function out = %s(in)\n', funname); %with function testit
fprintf(fid, ' out = in.^2;\n');
fprintf(fid, 'end\n');
fclose(fid);
clear(funname) % --> equivalent to clear testit
testit([1 2 3]) %executes new function
This would remove any existing pre-parsed testit function from memory so that you will get the new version of the .m file without risking MATLAB having remembered the old version.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by