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
2025 年 1 月 16 日
編集済み: Fangjun Jiang
2025 年 1 月 16 日
Can you press the "RUN" button in your example code section? "rxs" is not defined
採用された回答
その他の回答 (1 件)
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
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
clear data % Get rid of the variable from the workspace
load("data.mat") % Load it back in again
whos
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 Exchange で Propagation and Channel Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!