how can I plot nested structure fields?

6 ビュー (過去 30 日間)
nirmala rajagopal
nirmala rajagopal 2017 年 3 月 22 日
編集済み: Walter Roberson 2022 年 8 月 18 日
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

回答 (1 件)

Mehmet Burak Ekinci
Mehmet Burak Ekinci 2022 年 8 月 18 日
編集済み: Walter Roberson 2022 年 8 月 18 日
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;
% 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)")
% your data will be plotted in order of
% ht1.htr1, ht1.htr2, ht1.htr3, ht2.htr1, .... ht10.htr1, ht10.htr2,
% ht10.htr3


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!

Translated by