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

20 次查看(过去 30 天)
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 个评论
Elie Lusseau
Elie Lusseau 2023-2-21
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.

请先登录,再进行评论。

回答(1 个)

chrisw23
chrisw23 2023-2-21
try to start a new MatLab session
modify this cmd line as needed
matlab -wait -nodesktop -r "visdiff( \"\"{<file1>}\"\",\"\"{<file2>}\"\")"
  1 个评论
Elie Lusseau
Elie Lusseau 2023-2-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by