LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab script

Hi can anyone advise me on my error 1050.
The m files works in matlab though but not in labview.
0 Kudos
Message 1 of 11
(4,945 Views)

The m files does run in MATLAB because you have previously defined "banana" in MATLAB workspace. This error ecrtainly is not caused by LV. you should define all variables and functions in the script node.I think the problem comes from m file.

This is a part of MATLAB help file:

x = fminsearch(fun,x0) starts at the point x0 and finds a local minimum x of the function described in fun. x0 can be a scalar, vector, or matrix. fun is a function handle. See Function Handles in the MATLAB Programming documentation for more information.

Actually, I can't understand what fminsearch is supposed to do here!

0 Kudos
Message 2 of 11
(4,926 Views)
Hi thanks for ur reply.
  
The M-file
defines the function.
function f = banana(x)
f = 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
The statement
[x,fval] = fminsearch(@banana,[-1.2, 1])
should produce
x =
    1.0000    1.0000
fval =
    8.1777e-010
 
i wanted to see if i am able to run the function call in labview to get the desired result.
i reckon the problem lies in the inputs, but how do i define the inputs as you have mentioned?
please advise.
0 Kudos
Message 3 of 11
(4,915 Views)
This is the txt file.
0 Kudos
Message 4 of 11
(4,913 Views)

Oh, this 'banana' here is the banana's rosenbrock function. I was mistaking to interpret it as a variable. have you made an m file containing

function f = banana(x)
f = 100*(x(2)-x(1)^2)^2+(1-x(1))^2;

with the name of banana.m in Current MATLAB's working directory?

attached, you'll find the modified working versionSmiley Happy. remember that you must have banana.m in you working directory of MATLAB.

 

0 Kudos
Message 5 of 11
(4,900 Views)

Hi, do you mind to save another one in 7.0 version?

many thanks

 

0 Kudos
Message 6 of 11
(4,896 Views)
Previous VI in LV7.0
0 Kudos
Message 7 of 11
(4,894 Views)

Soroush,

The vi did not work for me. i had my m file placed in the matlab working directory.still return me the error 1050.i wonder where went wrong?

Beside that can you advise why you did not declare an input in the node? From the Lorenz differential example it did convert the file to string then string to array etc...  

0 Kudos
Message 8 of 11
(4,886 Views)
Hi celynn,
 
let us review.
 
We have a .m file in the current MATLAB working directory with this name: banana.m
(its name must be exactly banana.m)
 
that contains two lines like this:
 
function f = banana(x)
f = 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
 
when we open our fminsearch.vi in LV environment, a MATLAB command window will be opend (minimized style) that we must not close. If we close this command window, we will face error 1050 during vi execution.
Actually the matlab command window will be opened whenever you put a matlab script node on the block diagram of any vi. if you delete the script node from the block diagram or close the vi containing a matlab script node, that command window will be closed automatically. so do not close it.
 
now let us focus on the script itself. it is a one line script
 
[x,fval] = fminsearch(@banana,[-1.2, 1])
 
parameters 'x' and 'fval' are outputs of the fminsearch function. this function is defined in matlab and requires no definition by us. the only remained thing is @banana which is the function handle of "banana". we have already defined this function in a m file and matlab can find it in its working directory. it does not need to be defined here. banana is not an input. I'm afraid that I really can't understand what you mean by saying:
 
Beside that can you advise why you did not declare an input in the node? From the Lorenz differential example it did convert the file to string then string to array etc...  
 
There is no input in this string. banana is a function with one parameter. that parameter is a vector and the output is an scalar. in the script file we are calling fminsearch to find the minimum value of banana by trying different input vectors and the initial guess is [-1.2, 1].
we know that the minimum value of rosenbrock's banana function occures at [1 ,1] and is

zero. So whatever the initial state is, we will have a very small number as the result for fval and a vector with two elements so close to 1, as x.

If there is still any dark point let me know.  why and how do you want to relate Lorenz differential eq. to this script node? can you give a wider image of the main problem?

0 Kudos
Message 9 of 11
(4,879 Views)

Hi sorry for the late reply, the script works well now.

The Lorenz DE was the only example i can find in LV to illustrate the script node.U can see from the example that it actually convert the m file(function inside) to char ,string before input into the node.

My application will be similar to this fminsearch but the banana.m file(the equation) will be created in LV enviroment instead of a m file created in matlab.So how do i call the matlab script.node to do the fminsearch.Do i use write 'the equation' to a spreadsheet file in LV and convert to m.file or can i just input the equation into the input node?

0 Kudos
Message 10 of 11
(4,856 Views)