Reloading handle objects from .mat files

2 vues (au cours des 30 derniers jours)
Matt J
Matt J le 26 Mai 2023
Modifié(e) : Matt J le 31 Mai 2023
Why does isequal() return false when the reloaded handle is compared to the original handle, in the code below.
h=plot(1:5);
save tst h
h2=load('tst').h;
isequal(h,h2)
ans = logical
0

Réponse acceptée

Paul
Paul le 27 Mai 2023
Hi Matt,
It looks like two of the properties are changed, either on the save or on the load.
h=plot(1:5);
save tst h
h2=load('tst').h;
isequal(h,h2)
ans = logical
0
p = properties(h);
for ii = 1:numel(p)
if ~isequal(h.(p{ii}),h2.(p{ii}))
p{ii}
h.(p{ii})
h2.(p{ii})
disp(' ')
end
end
ans = 'Parent'
ans =
Axes with properties: XLim: [1 5] YLim: [1 5] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.1300 0.1100 0.7750 0.8150] Units: 'normalized' Show all properties
ans =
0×0 empty GraphicsPlaceholder array.
ans = 'DataTipTemplate'
ans =
DataTipTemplate with properties: DataTipRows: [2×1 matlab.graphics.datatip.DataTipTextRow] Interpreter: 'tex' FontSize: 10 FontAngle: 'normal' FontName: 'Helvetica'
ans =
DataTipTemplate with properties: DataTipRows: [2×1 matlab.graphics.datatip.DataTipTextRow] Interpreter: 'tex' FontSize: 10 FontAngle: 'normal' FontName: 'Helvetica'
I guess it makes sense for the Parent property to not be saved because it might not be in existence on the reload?
Not sure what's not isequal between the DataTipTemplates. Didn't drill down into DataTipRows

Plus de réponses (1)

Walter Roberson
Walter Roberson le 26 Mai 2023
f1 = figure(1);
ax1 = axes('Parent', f1);
h1 = plot(ax1, 1:10);
save tst f1
h1.YData(end) = 5
h1 =
Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [1 2 3 4 5 6 7 8 9 10] YData: [1 2 3 4 5 6 7 8 9 5] Show all properties
datastruct = load('tst');
f2 = datastruct.f1;
isequal(f1, f2)
ans = logical
0
f1.Number
ans = 1
f2.Number
ans = 2
double(f1)
ans = 1
double(f2)
ans = 2
f1.Children(1).Children(1).YData
ans = 1×10
1 2 3 4 5 6 7 8 9 5
f2.Children(1).Children(1).YData
ans = 1×10
1 2 3 4 5 6 7 8 9 10
Now, under your hypothesis, f1 (the live figure handle) should isequal() f2 (the retrieved saved version of the figure handle). But if they are isequal() then how would you account for the fact that the YData for the two needs to be different, since the plot for f1 was modified after it was saved? Should the retrieved copy have been updated to reflect the changes to f1, or should the active f1 have been regressed to reverse the changes so as to match the restored figure handle?
Or is it your position that when we modified the YData underneath the first figure, that the handle f1 should itself have changed?
  5 commentaires
Matt J
Matt J le 31 Mai 2023
Modifié(e) : Matt J le 31 Mai 2023
Which of the following is the mechanism you envision:
I don't have a vision. It was more of a question of what exactly is changing. It certainly isn't observed with general handle objects e.g.,
obj=myclass;
save tst obj
obj2=load('tst').obj;
isa(obj,'handle')
ans = logical
1
isa(obj2,'handle')
ans = logical
1
isequal(obj,obj2)
ans = logical
1

Connectez-vous pour commenter.

Catégories

En savoir plus sur Test and Measurement dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by