cellfun 関数を使って、セル配列の各要素を別々のグラフとして表示するにはどうすればよいですか?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 23 Jun 2020
Answered: MathWorks Support Team
on 23 Jun 2020
セル配列の各要素に、2次元配列が格納されています。
それぞれの各要素ごとに contour 関数で描画したいのですが、for ループを使用せずに、cellfun 関数を使って描画する方法を教えてください。
Accepted Answer
MathWorks Support Team
on 23 Jun 2020
例えば、1つの Figure 上に重ね書きを行いたい場合は、以下のように実行します。
% テスト用のデータを作成
C = cellfun(@(x)rand(10),cell(3),'UniformOutput',false);
figure
hold on
cellfun(@contour,C) % 各セルの要素に対して contour 関数を実行
また、subplot 関数を使って、別々の Axes に描画したい場合は、以下のように実行します。
[m,n] = size(C); % セル配列のサイズを取得
f = figure;
arrayfun(@(x)subplot(m,n,x),1:numel(C)); % subplot で Axes を作成
ax = flipud(findobj(f, 'Type','Axes')); % 描画順になるように反転
cellfun(@(ax,Z)contour(ax,Z),num2cell(ax),C(:)) % 各セル要素ごとにContour プロット
0 Comments
More Answers (0)
See Also
Categories
Find more on グラフィックス オブジェクト 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!