MATLAB: Cvhtml help

htmlmfile

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

Best Answer

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.