How can I change data directly from the plot ?

105 ビュー (過去 30 日間)
andrea
andrea 2020 年 5 月 12 日
コメント済み: andrea 2020 年 5 月 12 日
How can I divide the data on the first plot by 2 using command line ?
I mean is there a way like
ax = gca ;
ax.Children(2).Children(1).Ydata/2 ;

採用された回答

Mehmed Saad
Mehmed Saad 2020 年 5 月 12 日
編集済み: Mehmed Saad 2020 年 5 月 12 日
There are two axes in your figure (two subplots) and each axes contains three line
access the gcf
f = gcf;
Now to see how many childrens it has type on cmd
f.Children
ans =
4×1 graphics array:
Legend (2.5e-07-1e-06-5e-09 0.25, 5e-07-1e-06-5e-09 0.5, 1e-06-1e-06-5e-09 1)
Axes
Legend (1e-06-5e-07-5e-09 2, 5e-07-5e-07-5e-09 1, 2.5e-07-5e-07-5e-09 0.5)
Axes
So two axes and two legends
To access first axes
f.Children(2) % for 2nd axes use f.Children(4)
ans =
Axes with properties:
XLim: [5 40]
YLim: [0 1.6000e-06]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0.1300 0.1100 0.7750 0.3768]
Units: 'normalized'
Show all properties
to see its childrens
f.Children(2).Children
ans =
3×1 Line array:
Line (1e-06-1e-06-5e-09 1 )
Line (5e-07-1e-06-5e-09 0.5)
Line (2.5e-07-1e-06-5e-09 0.25)
Access first line Ydata
f.Children(2).Children(1).YData
ans =
1.0e-06 *
0.6266 0.3493 0.1950 0.1380 0.1078
To change it i.e. divide it by 2
f.Children(2).Children(1).YData = f.Children(2).Children(1).YData/2;
Similarly you can do that for other lines
  1 件のコメント
andrea
andrea 2020 年 5 月 12 日
Yes, is what I've done but the plot seems not refresh the data, is it possibel ?

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

その他の回答 (1 件)

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2020 年 5 月 12 日
To complement what Mehmed has just posted. It would be even easier if when you first create your figure, you save in handles all that is necessary, for instance:
x =[1 2 3 4];y=[4 3 2 3];
z = rand(8);
hFigure = figure(1);
hAxis1 = subplot(2,1,1);
hLines = plot(x,y);
hAxis2 = subplot(2,1,2);
hImage = imagesc(z);
Then you can modify your figure by modifying the data of the handles, say you want to change the image from z to z2 then you change it like this
z2 = randn(8);
hImage.CData=z2;
or like this
hAxis2.Children.CData = z2;
Hope that helps.

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by