how can I plot nested structure fields?
2 views (last 30 days)
Show older comments
I have the output as such:
>> y=spectrm(1).hata_pathloss_L50(1).ant_rec()
y = 197.1081 184.6407 175.9222
spectrm is a structure with fields 'freq', 'hata_pathloss_L50'{ht1, ht2, ht3} and receiver antenna height {htr1, htr2, htr3}. For each ht1, ht2 and ht3 there are htr1, htr2 and htr3 and for each freq there are ht1, ht2 and ht3. How to plot freq in x-axis and pathloss in y axis? the spectrm structure is also an array. say about 10. so there are around 10 freqs
0 Comments
Answers (1)
Mehmet Burak Ekinci
on 18 Aug 2022
Edited: Walter Roberson
on 18 Aug 2022
As far as i know there is no built in support for getting values or plotting nested structure arrays.
I recently uploaded my custom matlab functions in file exchange:
It is for plotting and getting values of large nested struct arrays and it applies to your problem.
clear spectrm
% create example struct array based on your explanation
for i = 1:10
spectrm(i,1).freq = i;
spectrm(i,1).hata_pathloss_L50(1).ant_rec = (1:3)*i;
spectrm(i,1).hata_pathloss_L50(2).ant_rec = (4:6)*i;
spectrm(i,1).hata_pathloss_L50(3).ant_rec = (7:9)*i;
end
% retreive struct array elements
freqs = getNestedField(spectrm,'freq');
losses = getNestedField(spectrm,'hata_pathloss_L50.ant_rec');
% use struct array plotter (you may also use "plot(freqs,losses)")
plotStructArray(spectrm,'hata_pathloss_L50.ant_rec',freqs);
% your data will be plotted in order of
% ht1.htr1, ht1.htr2, ht1.htr3, ht2.htr1, .... ht10.htr1, ht10.htr2,
% ht10.htr3
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!