Cannot use some Matlab MPC Toolbox functions - matlab

I'm trying to use for example setoutdist Matlab function from the MPC Toolbox (I'm using Matlab R2013a on Windows 8.1). As a response I'm receiving:
Undefined function 'setoutdist' for input arguments of type 'ss'.
I am able to get help about this function using help setoutdist. When I'm typing the function name and left parenthesis I'm receiving prompt with list of the arguments. When I'm using which setoutdist -all I'm receiving proper output:
C:\Program Files\MATLAB\R2013a\toolbox\mpc\mpc\#mpc\setoutdist.m % mpc method code here
But the function doesn't work even in default Matlab path, so I don't think it is shadowed.
The same is with the other functions, for example setindist, setestim, mpc_struct, etc. but mpc, mpcstate and mpcmove functions works correctly.
I was trying: clear all, clear classess, rehash toolbox, rehash pathreset, rehash toolboxreset, restoring default paths using pathtool. I've blocked the antivirus and added exeptions to it's list. I've even reinstalled my Matlab, nothing helped.
Maybe this is significant: when I'm trying to edit the setoutdist.m I'm receiving message that access is denied.
I will extremly appreciate any help...

How are you calling setoutdist? The correct syntax is one of the three (see documentation - for R2014b):
setoutdist(MPCobj,'integrators')
setoutdist(MPCobj,'remove',channels)
setoutdist(MPCobj,'model',model)
where MPCobj is a Model Predictive Controller object, created for example with the mpc function. It looks like from the error message that you are calling the function with a state-space object, which is not allowed (I'm guessing).

Related

How to call a Matlab function from Labview

I’m struggling to understand how to call a Matlab function from Labview. I’m using Labview 2020 SP1 and I’ve created the following m file (saved to my desktop):
function A = test()
A{1,1}=ones(1,3);
A{1,2}=ones(1,4);
end
In Labview I’ve added a Matlab script node and imported the function. However when I click run I get the following error:
Error occurred while executing script. Error message from server: ??? Error: Function definition not supported in this context.
Functions can only be created as local or nested functions in code files.
I was expecting the function to be able to run but do nothing as I’ve not added any outputs to the Matlab script node.
Can anyone point me to where I’m going wrong? I’ve looked through the Labview examples but they only seem to demonstrate calling a Matlab script not a function.
Firstly the function would need to be in MATLAB's path (which typically wouldn't include the current user's desktop). MATLAB's path is a list of file locations that MATLAB will search in to find a function definition.
You can view/edit the current path by typing pathtool into MATLAB's interactive command window which will bring up a GUI.
Then your MATLAB script node should be able to call the function as below - note I have added an output just to check the result of the call.
This image is a "LabVIEW Snippet" so you should be able to drag and drop it directly into the block diagram of a new VI and then save and run the VI.

Matlab corrplot function stopped working

The weirdest thing happened, it seems as Matlab corrplot function just stopped working. I have a piece of code which always worked perfectly fine. Now the same code is throwing an error. When I try
corrplot(CE,'varNames',{'Diam.','Depth','Rad.','Thick','Thin'})
I get:
Undefined function 'corrplot' for input arguments of type 'cell'.
The function is not deprecated, meaning that probably your Econometrics Toolbox is no longer available. You can check for the available toolboxes in your MATLAB license by running ver. Additionally you should run
which corrplot
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\econ\econ\corrplot.m
To show you whether it is around somewhere. I reckon something went wrong with the toolbox installation, so you should check whether you still have a valid license and, if so, reinstal the toolbox.
You might also have a variable called corrplot (which corrplot tells you whether that is the case) although in my case the error then is:
CE = [1:10].';
corrplot=1;
corrplot(CE,'varNames',{'Diam.','Depth','Rad.','Thick','Thin'})
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
which corrplot
corrplot is a variable. % Not good, you didn't want that.
Clear the variable with clear corrplot and check where in your code it creates this variable and rename it.

Open the m file for System Objects in MATLAB

I am trying to use the Communications Toolbox in Matlab. In this toolbox there are a number of built in Systems Objects for example
1) comm.PSKModulator
I want to examine the .m file and see how these system objects are implemented. So I wrote down the command
open comm.PSMModulator
However, that doesnt help. Does anyone know why it doesn't work or maybe one cant access such code?
Update
When I write down which comm.PSKModulator I receive the following
/Applications/MATLAB_R2014a.app/toolbox/comm/comm/+comm/PSKModulator.p % comm.PSKModulator constructor
and where I write open comm.PSKModulator I get
Error using open (line 146)
File associated with
'/Applications/MATLAB_R2014a.app/toolbox/comm/comm/+comm/PSKModulator.p' not found.
Thanks
Some System objects may be implemented in C++ and does not have much to show in MATLAB code which might be the reason this is p-coded. You need to check the corresponding Simulink block documentation for description of the algorithm used. You can find documentation for M-PSK Modulator Baseband at http://www.mathworks.com/help/comm/ref/mpskmodulatorbaseband.html which has more description about the algorithm implemented.

Undefined function or method 'nanvar_base' in Matlab

Somehow my Matlab does not has the function nanvar_base, needed to use the function ttest2 to calculate the t and p value of two sample data. How do I install that function? Is it missing to anyone else?
I had this same issue, the ttest2 function calling a nanvar function from SPM rather than the MATLAB statistics folder. A simple fix is going into 'change paths' in MATLAB and moving the SPM paths to the bottom of the list.
The function ttest2 is part of the statistics toolbox.
However, when I try to edit it, it does not show any calls to nanvar_base.
Did you perhaps try to edit it yourself, and in the process made a mistake? If this is not the case, try edit ttest2 and see where it is located and show the line with the call to nanvar_base.
This function isn't part of MATLAB or any of its toolboxes/add-ons. It must be custom functions. There is a function call nanvar however, in the Statistics toolbox and also in the Financial toolbox. Is this maybe the one you're after? If so, do you actually have the Statistics Toolbox and/or the Financial Toolbox?
the problem is probably another toolbox (like SPM) getting in the way, with their own 'nanvar' function.
Move SPM to the bottom of the path definition list, or remove it completely.
In general moving SPM have a lot of conflicting functions, so always make sure their path is at the bottom.
I had the same issue when calling the function nanvar, and realised that there was a conflict with a function with the same name in the Fieldtrip toolbox (this Fieldtrip function calls nanvar_base). After removing the Fieldtrip/src folder from my paths, it worked fine.

how a function change in a loop with newtonsys command matlab

i want to change function variable at each step in a for loop in matlab.
i take these steps:
i created my mfile function
function [jfun,fun]=air(x,vt,ty,tz,p2,y0)
jfun=[(cos(tz)*cos(ty)*vt/9.81)*(1-exp(-9.81*x(2)/vt)),...
x(1)*cos(tz)*cos(ty)*exp(-9.81*x(1)/vt);
(-vt*sin(tz)*cos(ty)/9.81)*exp(-9.81*x(1)/vt),...
(x(1)*sin(tz)*cos(ty)*+vt)*exp(-9.81*x(1)/vt)];
fun=[(x(1)*cos(ty)*cos(tz)*vt/9.81)*(1-exp(-9.81*x(2)/vt))-p2;...
(vt/9.81)*(x(1)*sin(tz)*cos(ty)+vt)*(1-exp(-9.81*x(2)/vt))-vt*x(2)+y0];
end
and then i used newtonSys command:
ty=rad(-23)
tz=rad(15)
p2=1.8
vt=8.4925
y0=0.2
myfun=#(x)air(x,vt,ty,tz,p2,y0)
x=newtonSys(myfun,[15 5],0.000001,0.000001,500,1)
and matlab answer:
Error in ==> Untitled18 at 7
x=newtonSys(myfun,[15 5],0.000001,0.000001,500,1)
i guess that its because of wrong use of function handle and for my function i have to use another command or i have to use another method for solving 2nonlinear equation.
First, you haven't displayed the entire error. MATLAB should tell you what the actual error is, so unless you tell us that, we won't know what's wrong.
Secondly I don't see newtonSys in my system, or in the online MATLAB documentation. So most likely it is an external program, which most people here might not be familiar with. The closest I found from a quick Google search was this, which is an implementation of Newton's method for approximating the root of a non-linear system of n-equations. Are you using the same file? If so, if you look at the comments, it says that you need to pass the function as a string. So you'd have to pass myfun as 'myfun'.
If not, could you edit your question and add the contents of the function that you're using? Without these, it's near impossible to answer your question.