Use the variable of function for title of a figure

4 ビュー (過去 30 日間)
Simon Rinn
Simon Rinn 2020 年 9 月 14 日
コメント済み: Image Analyst 2020 年 9 月 14 日
Hi,
I want to use the variable of my function which is a structure as the title of a figure. For example I do :
a = fullplot ( name_struc)
%The function is defined as :
function [] = fullplot(struc)
e = struc.xaxis
s = struc.yaxis
plot(e,s)
title ( ' XXX ' )
end
Instead of the 'XXX' i want to put 'name_struc'.
I tried with inputname(1) but this return 'struc' and not 'name_struc' .
Can someone help me please ?
Thank you

採用された回答

Image Analyst
Image Analyst 2020 年 9 月 14 日
編集済み: Image Analyst 2020 年 9 月 14 日
This seems to work fine:
name_struc.xaxis = 1:20;
name_struc.yaxis = rand(1, 20);
a = fullplot ( name_struc)
%The function is defined as :
function a = fullplot(struc)
e = struc.xaxis
s = struc.yaxis
plot(e,s)
title (inputname(1), 'Interpreter', 'none', 'FontSize', 20)
a=1; % Some output.
end
You see, it has a title of name_struc, not struc.
  2 件のコメント
Simon Rinn
Simon Rinn 2020 年 9 月 14 日
Yes you are right the mistake come from me.
Thank you very much for this very quick answer.
Image Analyst
Image Analyst 2020 年 9 月 14 日
No problem. Thanks for Accepting.

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 9 月 14 日
Are you sure? put inputname(1) inside the function. It should show name as "MyStruct" if you call it with fullplot(MyStruct)
  1 件のコメント
Simon Rinn
Simon Rinn 2020 年 9 月 14 日
Yes you are right. The mistake comes from me.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by