I want the name of my variables in a plot legend in matlab. Is this possible?
my example is:
function example(x1)
figure;
plot(x1.time, x1.value);
legend(x1);
end
now I want to call my function like:
>> example(myvariable)
my legend should look like:
---------------
| -- myvariable |
---------------
thanks for your help guys.
You can use inputname
to get the name of the input in the calling workspace and then pass this to legend
or set the DisplayName
property of the plot to this value.
function example(x1)
figure
plot(x1.time, x1.value)
legend(inputname(1))
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.