Code covered by the BSD License  

Highlights from
STRUCTCOMPVIS

3.5

3.5 | 2 ratings Rate this file 13 Downloads (last 30 days) File Size: 1.7 KB File ID: #7348
image thumbnail

STRUCTCOMPVIS

by Scott Hirsch

 

01 Apr 2005 (Updated 06 Jan 2010)

Use visual differencing tool to compare two structures.

| Watch this File

File Information
Description

---------------------------
STRUCTCOMPVIS(s1,s2) opens an HTML differencing report comparing two structures.

This is useful for quickly finding subtle differences between 2 structures. I find it particularly useful when working with large handles structures from GUI applications.

Ex:
% Find which properties are different between two graphics objects
subplot(211);l1 = plot(1:10)
subplot(212)l2 = plot(1:10,'r')
structcompvis(get(l1),get(l2))
---------------------------

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
10 Jan 2006 David Epstein

A tremendous help when trying to debug handle graphics scripts.

07 Feb 2011 Andrew Newell

I ran into a few problems running this code:
  1. It uses the directory given by the environment variable TEMPNAME. Oddly, though, TEMPNAME is incorrect on my machine.
  2. It calls VISDIFF, which works asynchronously. As a result, STRUCTCOMPVIS deletes the temporary files before VISDIFF has managed to open them.
  3. It displays the contents of the structures in the command window as well as the comparison window.
  4. The issue regarding lengths of field names is due to an unnecessary parameter handed to VISDIFF.

Here is some code that fixes all these problems:

% Sort structures, to ignore order
s1 = orderfields(s1);
s2 = orderfields(s2);

% Write structures to temp files
structInStringFormat = evalc('disp(s1)');
f1 = tempname;
fid = fopen(f1,'w+');
fprintf(fid,'%s\n',structInStringFormat);
fclose(fid);

structInStringFormat = evalc('disp(s2)');
f2 = tempname;
fid = fopen(f2,'w+');
fprintf(fid,'%s\n',structInStringFormat);
fclose(fid);

% Use visual differencing report
visdiff(f1,f2)
pause(1)

% Delete temp files. Feel free to keep these.
delete(f1)
delete(f2)

07 Feb 2011 Andrew Newell

Oops - I mistakenly wrote TEMPNAME above in place of TEMPDIR. Also, the issue seems to be my fault because I changed TEMPDIR while debugging this code. However, I think it is cleaner to use TEMPNAME to create the file names. Either way, the file names displayed by VISDIFF will generally not correspond to the user's variable names.

Please login to add a comment or rating.
Updates
06 Jan 2010

Updated copyright.

Tag Activity for this File
Tag Applied By Date/Time
structures Scott Hirsch 22 Oct 2008 07:44:51
cell arrays Scott Hirsch 22 Oct 2008 07:44:51
structure Scott Hirsch 22 Oct 2008 07:44:51
compare Scott Hirsch 22 Oct 2008 07:44:51
visual Scott Hirsch 22 Oct 2008 07:44:51
diff Scott Hirsch 22 Oct 2008 07:44:51
difference Scott Hirsch 22 Oct 2008 07:44:51

Contact us at files@mathworks.com