How to create Plot button for Complex vector?
显示 更早的评论
I would like to be able to highlight a complex vector in the workspace and be able to click a button to plot complex vector the way the following function works:
PTRIn = @(x) plot(1:length(x), real(x), '-b', 1:length(x), imag(x),'--g');
If I highlight a variable in the Workspace, and hit the plot button, I do not get the desired plot. (Looks like imag vs real). If I hit the stem button, I get msg: "Warning: Using only the real component of complex data."
I have releases R2020a, R2021a, R2021b, and R2022a.
6 个评论
Geoff Hayes
2022-6-11
@Paul Hoffrichter - so you would like to add your function to the plot catalog? i.e. that list of plots that appear when you select the variable and bring up the menu?
Paul Hoffrichter
2022-6-11
Paul Hoffrichter
2022-6-12
Geoff Hayes
2022-6-12
@Paul Hoffrichter- I don't think you can add custom plot functions to the plot "catalog" (whether you access this from the menu PLOTS tab or elsewhere. I guess I don't understand what you mean by I just don't want to be editing my code all the time by adding this function (or even adding global functions) or eliminates the need for me to add the PTRIn(x) function to each function. What are the other functions?
Jan
2022-6-12
Where should this button appear?
Paul Hoffrichter
2022-6-13
编辑:Paul Hoffrichter
2022-6-13
>> I just don't want to be editing my code all the time by adding this function (or even adding global functions) or eliminates the need for me to add the PTRIn(x) function to each function.
To clarify... Say I have 100 functions. None of them have the PTRIn function defined in them. If examining, say, 6 of those functions, then in order to plot the complex valued vectors, I have to add PTRIn definition temporarily in those 6 functions and remove them later. Or, I can define it in the command window. I'd rather have a way where PTRIn is always defined so I don't have to keep defining it on an ad hoc basis. Would have been nice to have a PLOT button that has PTRIn defined.
>> Where should this button appear?
Anything that would help with my stated goal is better than what I do now. So, anywhere I guess. Would be nice to have a PLOT button that plots both the real and imag parts in one figure. Barring that it would be nice to a button that defines PTRIn in the command window without my having to copy and paste from my notepad.
采纳的回答
更多回答(1 个)
I am fairly certain that it is not possible for users to register their own plotting functions for inclusion in the Plots Catalog on the Plots tab of the toolstrip.
If you have defined PTRIn as its own function then you can call it in the Command Window using any data that is in scope (so if you're stopped in the debugger, any data accessible to the function that you're debugging is fair game. I'm being intentionally vague or general here when I say "accessible".) If you have a hard and fast requirement that this be accessible via a button click, could you share why you have that requirement? Is it for accessibility, is it so you can keep keyboard focus in a particular window, is it because you're hoping to run this in an environment (like a deployed application) where the Command Window is not available, or is there some other reason?
Your eval based solution makes me a bit nervous, but if you really want to be able to click on a button you could create a favorite to run that code. To simulate you selecting the text 'x' in your code and copying it to the clipboard I'm using the clipboard function. You would then use eval in conjunction with clipboard('paste') to access the variable. Note that I am not responsible if you were to highlight, for example, some text that when evaluated closes MATLAB or does other nasty things.
x = 1:10;
clipboard('copy', 'x')
plot(eval(clipboard('paste')))
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

