How to properly using visdiff in command line with mat files ?

12 views (last 30 days)
Hello all,
I am trying to compare m files that contains parameters that are not stored in specific lines.
The only way to do so I found is to :
  • Run the first m file manually and save resulting workspace in a first mat file
  • Run the second m file manually and save resulting workspace in a second mat file
  • right clic with both selected and use compare option
  • Analyse the differences (my real goal/activity)
  • Deleting the mat files
As the overall process of having a GUI is a pain and not really adding value, I am trying to automating evrey step.
But when programmatically compare 2 sets of matlab variables that are stored in temporary mat files.
(My code stores the files in a temp directory so that once the comparison is done, I can delete them.)
Here is a simplified version of my code :
tmpfolder = tempname;
file1 = horzcat(tempname(tmpfolder), '.mat');
file2 = horzcat(tempname(tmpfolder), '.mat');
% file1 and file2 are filled with data
visdiff(file1, file2);
% want to wait here
rmdir(tmpfolder, 's');
The difficulty is that as soon as I run the rmdir command, the visdiff interface freeze and the result of the comparison even does not show up.
Am I doing something the wrong way ?
(Maybe visdiff is not the right tool)
Is there a way to make my code wait for the finished comparison to go to the rmdir command ?
(I already tried the pause(N) and a loop based on desktop = com.mathworks.mde.desk.MLDesktop.getInstance(); but both does not work)
Thanks in advance.
Best regards.
  2 Comments
Elie Lusseau
Elie Lusseau on 21 Feb 2023
tmpfolder = tempname;
file1 = horzcat(tempname(tmpfolder), '.mat');
Is used to create a file in a temp folder that I will be able to delete at the end.
tempname create a folder in %temp% with a unique name.
tempname(tmpfolder) create a unique file name in the said folder.

Sign in to comment.

Answers (1)

chrisw23
chrisw23 on 21 Feb 2023
try to start a new MatLab session
modify this cmd line as needed
matlab -wait -nodesktop -r "visdiff( \"\"{<file1>}\"\",\"\"{<file2>}\"\")"
  1 Comment
Elie Lusseau
Elie Lusseau on 21 Feb 2023
Thanks for the answer
By modifying the command this way :
system(['matlab -wait -nodesktop -r "visdiff(''', file1, ''', ''', file2, ''')'])
I manage to run a proper separate matlab environment.
Unfortunately, I retrieve an error pop-up (not in command windows) :
Error : Connector is not running. Use connector.ensureServiceOn() to ensure it is running before using it.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!