cvhtml help

3 views (last 30 days)
Lucas
Lucas on 6 Jun 2012
Commented: Walter Roberson on 21 Feb 2020
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

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jun 2012
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 Comments
Tonmoy Roy
Tonmoy Roy on 19 Feb 2020
Hi Walter, I am not sure what you meant by use "clear" on the function name. Can you explain further?
Walter Roberson
Walter Roberson on 21 Feb 2020
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!