save() seems to be saving objects that should be destroyed, causing errors when the resulting .mat file is loaded

4 ビュー (過去 30 日間)
Example code:
txs = txsite("AntennaHeight",1.5, ...
"Latitude", 38.9899587, "Longitude", -76.9353889, ...
"TransmitterPower", 10);
rxs = rxsite("AntennaHeight", 1.5, ...
"Latitude", 38.9860195, "Longitude", -76.9412203);
pm = propagationModel('raytracing');
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec'd power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [RSS, phaseOffset];
end
close all force % this is an attempt to fix this issue
save("data.mat","data")
The above code works as expected however, running:
load("data.mat")
Will result in the following warnings being spammed in the console:
> In <FUNCTION> (line 25)
Warning: Unable to load C++ object. Saving (serializing) C++ objects into a MAT-file is not supported.
> In <FUNCTION> (line 25)
Warning: Cannot load an object of class 'proplistener':
No matching constructor signature found.
> In <FUNCTION> (line 25)
Warning: During load:
An invalid default object has been detected while loading a heterogeneous array of class event.proplistener. An empty array of
class event.proplistener will be returned.
> In <FUNCTION> (line 25)
Warning: While loading an object of class 'siteviewer':
Unrecognized field name "Name".
I thought foriclby closing the siteviewer would work (or at least get rid of the last error), but it has not seemed to have an effect. What command should I run to fix this behavior?
Tested on 2023b, 2024b and the 2025 prerelease across two computers (one Win10, one Ubuntu22) which both had similar behaviors, although the Windows mahcine produced far fewer warnings.
  4 件のコメント
Fangjun Jiang
Fangjun Jiang 2025 年 1 月 16 日
編集済み: Fangjun Jiang 2025 年 1 月 16 日
Can you press the "RUN" button in your example code section? "rxs" is not defined
Alex B
Alex B 2025 年 1 月 16 日
works now, line 3 shoudlve been rxs = rxsite(...)

サインインしてコメントする。

採用された回答

Alex B
Alex B 2025 年 1 月 28 日
編集済み: Alex B 2025 年 1 月 28 日
As an update on this I fixed everything except the "Unrecognized field name: Name" warning by just opening and saving the file again after creation. This issue also only seems to occur on files created using my work (Ubuntu) comptuer, my personal (Windows) computer does not do this. I am still not sure what bad objects it was attempting to save.
Unfortunately, it seems like the final error can only be fixed by specifying the site name when the data is created - attempting to do something like:
site = siteviewer()
site.Name = "Test"
save("test.mat",site)
load("test.mat")
Will result in the warning:
Warning: While loading an object of class 'siteviewer':
Dot indexing is not supported for variables of this type.
when saving or loading the respecitve file.
Edit:
Also, upon clearing the variable scen you will get:
Warning: The following error was caught while executing 'matlab.internal.asynchttpsave.AsyncHTTPContentFileWriter' class destructor:
Output argument "result" (and possibly others) not assigned a value in the execution with "matlabshared.asyncio.internal/Channel/isOpen" function.
Error in matlab.internal.asynchttpsave.AsyncHTTPContentFileWriter/cancelAndCloseChannel
Error in matlab.internal.asynchttpsave.AsyncHTTPContentFileWriter/delete

その他の回答 (1 件)

Steven Lord
Steven Lord 2025 年 1 月 16 日
txs = txsite("AntennaHeight",1.5, ...
"Latitude", 38.9899587, "Longitude", -76.9353889, ...
"TransmitterPower", 10);
When I ran the raytrace function it complained that the variable rxs was unrecognized. Since you defined a variable txs twice, I'm assuming the second one was supposed to be rxs and use rxsite instead of txsite.
rxs = rxsite("AntennaHeight", 1.5, ...
"Latitude", 38.9860195, "Longitude", -76.9412203);
pm = propagationModel('raytracing');
rays = raytrace(txs, rxs, pm, "type", "power"); % rays is Na x Ns cell array
if ~isempty(rays{1}) % only ever 1 tx/1 rx
rayPower = 0;
% phasor sum of rec'd power
for rayPath = 1:numel(rays{1})
pWatts = 10^(-rays{1}(rayPath).PathLoss/10)*10;
rayPower = rayPower + pWatts*(cos(rays{1}(rayPath).PhaseShift) + 1i*sin(rays{1}(rayPath).PhaseShift));
end
% convert to RSS in dBm and resultant signal phase offset
RSS = 10*log10(abs(rayPower)/.001); % dBm
phaseOffset = angle(rayPower) ; % rads
% collate data
data = [RSS, phaseOffset];
end
Let's see what variables are in the workspace right now.
whos
Name Size Bytes Class Attributes RSS 1x1 8 double data 1x2 16 double pWatts 1x1 8 double phaseOffset 1x1 8 double pm 1x1 1250 rfprop.RayTracing rayPath 1x1 8 double rayPower 1x1 16 double complex rays 1x1 2632 cell rxs 1x1 8 rxsite txs 1x1 8 txsite
Now we can save the data variable and try to reload it.
cd(tempdir)
save("data.mat", "data")
whos -file data.mat % check which variable are in the MAT-file
Name Size Bytes Class Attributes data 1x2 16 double
clear data % Get rid of the variable from the workspace
load("data.mat") % Load it back in again
whos
Name Size Bytes Class Attributes RSS 1x1 8 double data 1x2 16 double pWatts 1x1 8 double phaseOffset 1x1 8 double pm 1x1 1250 rfprop.RayTracing rayPath 1x1 8 double rayPower 1x1 16 double complex rays 1x1 2632 cell rxs 1x1 8 rxsite txs 1x1 8 txsite
Since there's no warnings issued by this load call, there must be something different about the actual code you're running from what you posted. Did you perhaps call save with just the name of the MAT-file to be saved?
save("data2.mat")
load("data2.mat") % No warnings
clear all
load("data2.mat") % Still no warnings
I think you're going to need to show us the body of your <FUNCTION> function.

カテゴリ

Help Center および File ExchangePropagation and Channel Models についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by