Plotedit state of a Matlab figure - matlab

How can I extract the plotedit state of a Matlab figure inside a function? If I want to know the zoom state of the current figure, I can write:
zoomState = get(zoom(gcf), 'Enable');
A similar syntax for plotedit does not work, since plotedit(gcf) toggles the plotedit state without returning anything. Without having a way to get plotedit's current state, I have no clue how to temporarily put it to 'off' and restore its value once my function has finished. Any ideas?

I just received an answer from the MathWorks on this issue:
here is an undocumented feature that you might want to use :
ison = plotedit(gcf,'isactive')
This will tell you if PLOTEDIT is active or not. However, since this
is undocumented it might change or not work in future releases.
I think that this answers my question.

If you type open plotedit at the command line, you will see that it is actually an m-file. When the state is toggled, it calls the undocumented function activateuimode to do the dirty work. Taking a wild guess, I typed help getuimode at the command line and got back the message
This function is undocumented and will change in a future release
So the function exists. Presumably, calling it with the same input arguments as activateuimode in plotedit will do what you want. That is,
getuimode(myFigHandle, 'Standard.EditPlot')
On my system, it returns [] if not in edit mode, and an instance of uitools.uimode if it is.
Note, however, that this approach may be a bit dodgy - as the help says, it will probably change in a future release. If you open getuimode, you will see it has been the same since 2007, but as I understand it there has been a major overhaul of the UI system in R2013, so it may have changed in the most recent release (I'm running R2012a).

Related

Does ever calling `check()` on a capability panic?

According to the docs there is no reference of check panicking in any situation, but I would like to know if there is any edge case where this method could panic rather than returning false.
AFAICS, there are currently two cases where check() may fail:
The path leads to a cycle (see https://github.com/onflow/cadence/issues/2264)
Not sure: The code/type of the stored value is broken and cannot be loaded
Please feel free to open an issue in the Cadence repository if you think this should be changed, and especially why. Thanks!

How to change LabVIEW Control value (in already running VI) via Active X?

I am trying set a control value in my VI (which is already running).
I use the following commands:
e=actxserver('LabVIEW.Application');
vipath='C:\DATA\Labview\test.vi';
vi=invoke(e,'GetVIReference',vipath);
% my control parameter is z which is DBL (double precision)
vi.SetControlValue('z',10)
Everything seems to work fine ! I can see the 'z' value change to 10 in VI but actually VI is not reading that value and VI application is not responding to this value
The VI is a third party application, which is developed by someone else. Unfortunately, I don't have privilege in this forum to post a picture of it (I need 10 points)
I am trying to control variable "z" from Matlab. The "z"is an input to a .dll file. Note that I can do it by front panel control in VI, but can't using Matlab as described earlier.
Without seeing the code, it's impossible to tell, but here are a couple of guesses:
Are you reading the control using a value change event? This event is only triggered either by a change in the UI or by calling the Value(Signaling) property for the control. I'm not sure if you can access this property from the ActiveX interface, but you can try by getting a reference to the control (although I have no idea how that's done from the ActiveX interface either. Maybe the VI has a method?). If you can't, the best would probably be to change the VI to poll the control. You could also have another loop which will fire the event whenever the control changes, but if you do that, I would suggest you have a separate control just for passing that value.
Another possibility - the value is read from the control's terminal before you modified it and your code uses the value on the wire, not the value from the control.
If that doesn't help, post the code.
Got it ! The control variable 'z' was within a event structure, and it was set to value change of 'z'. So, I just removed it for the time being and it works well.
However, I am not sure how to work with an event structure to control it using Matlab active x

MATLAB Engine: engEvalString() won't return if given incomplete input

I'm using the MATLAB Engine C interface on OS X. I noticed that if engEvalString() is given an incomplete MATLAB input such as
engEvalString(ep, "x=[1 2");
or
engEvalString(ep, "for i=1:10");
then the function simply never returns. The quickest way to test this is using the engdemo.c example which will prompt for a piece of MATLAB code and evaluate it (i.e. you can type anything).
My application lets the user enter arbitrary MATLAB input and evaluate it, so I can't easily protect against incomplete input. Is there a workaround? Is there a way to prevent engEvalString() from hanging in this situation or is there a way to check an arbitrary piece of code for correctness/completeness before I actually pass it to MATLAB?
As you noted, it seems this bug is specific to Mac and/or Linux (I couldn't reproduce it on my Windows machine). As a workaround wrap the calls in eval, evalc, or evalin:
engEvalString(ep, "eval('x = [1,2')")
Furthermore, an undocumented feature of those functions is that they take a second input that is evaluated in case an error occurs in the first one. For example:
ERR_FLAG = false;
eval('x = [1,2', 'x=nan; ERR_FLAG=true;')
You can trap errors that way by querying the value of a global error flag, and still avoid the bug above...
This was confirmed by support to be a bug in the MATLAB Engine interface on OS X (it's not present in Windows). Workarounds are possible by using the MATLAB functions eval, evalc, or similar. Instead of directly passing the code to engEvalString(), wrap it in these first.

ButtonDown event does not work sometimes matlab

I have two textboxes and a button in matlab. Designed the form using GUIDE. I used the following code to copy value from one textbox to another. The code works sometimes and not always. I am not able to find the scenario in which it works and what was wrong with this code.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
myTextBox1 = findobj('Tag','edit1');
myTextBox2 = findobj('Tag','edit2');
str = get(myTextBox1,'String');
set(myTextBox2,'String',str);
Given the comments it is safe to say that nothing is wrong with this piece of code.
This is not yet a solution, but it seems clear that you are searching in the wrong place.
Two things that you want to check:
The state your program is in at the time the function is called, maybe there is something strange going on with the relevant variables.
Whether there is a problem with the availability of files that you use as input, if you use a file right after it is updated this may be a cause of problems.
It worked when i gave the code in pushbutton1_Callback(...) function. Thanks.

Matlab GUI callback Warning

All GUI components Callback functions have function might not be used warning.
I know it sound silly for most of programmers to care about such silly warnings when code is running okay, but I wonder why matlab emit such a warning although the function is called when the button is clicked, or whatever component Callback event happens.
Can anyone here explain how to fix this warning? or why this even happens?
Hint: I am using Matlab R2011a , if it differ for one version to another.
The solution is to add this string %#ok<DEFNU> at the end of function definition line to to disable might not be used warning in this line or %#ok<*DEFNU> to disable this warning type in current file.
And it indicates that no warning and this issue is okay in the run time.