How to plot elements of a structure?

6 ビュー (過去 30 日間)
Alex
Alex 2018 年 9 月 13 日
編集済み: Alex 2018 年 9 月 14 日
I have an array of structures that is 91x10 called B. Within each element of the array is a structure Bx, By, Bz. I want to create three pcolor plots of Bx, By and Bz. I'm not sure how to do this.
latitudes =1:1:10;
alt=1:1:91;
for j=1:length(latitudes)
for i=1:length(alt)
B_igrf(:,1) = rand(3,1)
B(i,j)=struct('Bx',B_igrf(1,1),'By',B_igrf(2,1),'Bz',B_igrf(3,1))
end
end
%map Bx
figure(2),pcolor(latitudes, alt, B.Bx)
xlabel('Time(time past.......','fontsize',24, 'fontweight','bold')
ylabel('Altitude (km)','fontsize',24, 'fontweight','bold');
xlabel(colorbar,'n_e(m^{-3})','fontsize',24, 'fontweight','bold')
set(gca,'FontSize',24)
Your help would be greatly appreciated!
  2 件のコメント
Bob Thompson
Bob Thompson 2018 年 9 月 13 日
As I understand it, when you want to work with all the elements of a field in a structure you need to concatenate them. Try:
pcolor(latitudes, alt, [B.Bx]);
No guarentees, just the first thing that came to mind.
If that doesn't work, are you getting any errors? If so, what are they?
Alex
Alex 2018 年 9 月 14 日
編集済み: Alex 2018 年 9 月 14 日
The command you suggested gives the error "Color data input must be a matrix."
I solved the issue by using:
% magnetic field data
latitudes =1:1:10;
alt=1:1:91;
for j=1:length(latitudes)
for i=1:length(alt)
B_igrf(:,1) = rand(3,1)
Bx(i,j)= B_igrf(1,1);
By(i,j)= B_igrf(2,1);
Bz(i,j)= B_igrf(3,1);
end
end
% map Bx
figure(2),pcolor(latitudes, alt, Bx)
figure(3),pcolor(latitudes, alt, By)
figure(4),pcolor(latitudes, alt, Bz)

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by