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

조회 수: 13 (최근 30일)
Elie Lusseau
Elie Lusseau 2023년 2월 21일
편집: Elie Lusseau 2023년 2월 21일
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
Fangjun Jiang
Fangjun Jiang 2023년 2월 21일
What do you try to do by "tempname(tmpfolder)"??
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에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by