LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Matlab script in Labview

the remaining ones..

GARCH Toolbox                                         Version 2.0.1      (R14SP1)
Gauges Blockset                                       Version 2.0        (R14SP1)
Genetic Algorithm Direct Search Toolbox               Version 1.0.2      (R14SP1)
Image Acquisition Toolbox                             Version 1.7        (R14SP1)
Image Processing Toolbox                              Version 5.0.1      (R14SP1)
Instrument Control Toolbox                            Version 2.1        (R14SP1)
Link for Code Composer Studio                         Version 1.3.2      (R14SP1)
Link for ModelSim                                     Version 1.2        (R14SP1)
MATLAB Builder for COM                                Version 1.1.2      (R14SP1)
MATLAB Builder for Excel                              Version 1.2.2      (R14SP1)
MATLAB Compiler                                       Version 4.1        (R14SP1)
MATLAB Report Generator                               Version 2.1.1      (R14SP1)
MATLAB Web Server                                     Version 1.2.3      (R14SP1)
Mapping Toolbox                                       Version 2.0.3      (R14SP1)
Model Predictive Control Toolbox                      Version 2.1        (R14SP1)
Model-Based Calibration Toolbox                       Version 2.1.2      (R14SP1)
Neural Network Toolbox                                Version 4.0.4      (R14SP1)
OPC Toolbox                                           Version 1.1.1      (R14SP1)
Optimization Toolbox                                  Version 3.0.1      (R14SP1)
Partial Differential Equation Toolbox                 Version 1.0.6      (R14SP1)
RF Blockset                                           Version 1.0.2      (R14SP1)
0 Kudos
Message 11 of 24
(1,884 Views)
Whoa, that looks like about 50k worth of software you've got there (doh!, you posted three pages of addons. I'll revise my estimate to $250k!). I noticed that some are blocksets, which means they are additions to Simulink. I have no experience using Simulink from LV, so I wonder if that may be a problem that you are running in to. I don't see anything in your code that involves Simulink though (but I don't have MATLAB installed on the machine I am at, so I can't test your code).

I just spoke to one of our MATLAB guys (if I was a MATLAB guy, I probably wouldn't be here...) and he suggested setting your array inputs to complex. He said he remembered a bug in LV7.1 that required him to use complex arrays for his inputs once. Right now, you don't have any inputs, so it would seem like this would work (at least it should work as well as it does in MATLAB). To create an input, right-click on the edge of the M-script node and select an input type.

If your script works in MATLAB, but not in LV, try commenting out bits of it until you can narrow down to the exact few lines in your script that are causing problems. LV shouldn't really care about the content of your script; it's primarily concerned with the inputs and outputs. If both of those work, I think there is something else going on.
Chris

Message Edited by C. Minnella on 09-19-2006 09:52 AM

0 Kudos
Message 12 of 24
(1,884 Views)
im using the university's comp..

im now trying the existing input that is written with the codes.. what type of output should i get??

in my codes

A = [[-1 -1];[-.5 .3];[.89 1.2];[1 -.8]];

B = [[-.5 -.5];[-.5 .5];[.5 .5];[.5 -.5]];

im not so sure how to do bit by bit as my program is all related ... could u give me some idea as in which part.. i only can get the out put A and B ... when i go into the third line .. it gives me 0..
 thanks
0 Kudos
Message 13 of 24
(1,877 Views)
hi ,, i've tried entering the codes bit by bit .. the strange thing is that it only works when i initialize the arrays
A = [[-1 -1];[-.5 .3];[.89 1.2];[1 -.8]];

B = [[-.5 -.5];[-.5 .5];[.5 .5];[.5 -.5]];

but when i try to get the length of the array
C = length(A)
D = length(B)

.. i don't get any output .. it's 0 ... i really dont know how to debug it from here
please help me .. thanks..
0 Kudos
Message 14 of 24
(1,871 Views)
Try this vi. It is a very simple vi that takes your two arrays and sends them into a M-script node. Inside the node, MATLAB gets the length of each array (I prefer to use size() because it is not always clear what dimension you are going to get with length()...) and outputs out of the node to LabVIEW. See if this works.

chris
0 Kudos
Message 15 of 24
(1,867 Views)
hi chris.. i tried the codes in another comp .. it worked but only half way ...
 
when the code comes to something called 'nargin', it doesnt work anymore .
 
and the stange thing is that .. the half way codes that worked .. after i saved and exited .. it doesnt work when i reopen it ..  
 
i want to ask .. when i want to run matlab codes in labview.. do i just open matlab and leave it there or do i have to do something else ..
 
does labview 7.1 support only particular version of matlab ?
 
thanks
0 Kudos
Message 16 of 24
(1,856 Views)
nargin only works in functions. I think your m-code is a script, so I wouldn't expect that to work. You should confirm that your code works in MATLAB before trying it in LabVIEW. When you load a vi with an m-script node, LabVIEW will automatically launch a MATLAB command console. If it somehow loses it's connection to the command console (for example, if you close it) it will give you an error about communicating with the script server. Either quit LV and open everything back up, or you can manually reload the command console by temporarily switching your script node from MATLAB to xmath and back by right-clicking on it. There is probably a better way, but that worked for me.

Chris
0 Kudos
Message 17 of 24
(1,852 Views)
hi chris ..

i modified the codes and managed to get it running ... it works fine ..

but the strange thing is that it doesn't work the same for different comps.

i did matrix transpose successfully in one comp . but the other doesnt recognize it ..

my matlab codes take in n by 2 matrix .. but in labview .. the array can be (n by 2) or (2 by n)  how do i deal with it ??  do i need to tranpose  them in matlab?

should  i post my program here ?

i've got a problem here...

my centroid is in a cluster .. so when i get four centroids , i will have a 4-cluster array .. how can i modify to input to matlab codes?

thanks chris .  i've done quite alot with your help ....
0 Kudos
Message 18 of 24
(1,849 Views)
Hey Kupikupi, I'm glad some of my rambling has helped. Feel free to throw some stars my way (Rate this message *****) Smiley Happy. As far as handling the array dimensions, that kind of goes back to what I said about size() vs. length() in matlab. I think length gives you the size of the longest dimension, whereas size() returns the size of all dimensions. I would use size() to check the dimension of your inputs, and use a conditional to transpose them if necessary. That way, your code can handle any inputs.

Also, to handle your cluster inputs, you'll want to manipulate that into some sort of simpler datatype. Let me get this straight: you've got each centroid in a cluster (what's in the cluster?) and multiple centroids are in an array. Assuming your centroid cluster is a cluster of two doubles (X & Y), you could convert your cluster array into a 2-D double array for input to the m-script node. If this sounds about right, I can help you with it if necessary. You'll want to put your cluster array into a for loop, and for each element, unbundle and build a 1-D array of doubles. That will be output from the for loop as a 2-D array of doubles that can be input into your m-script node just like in the last example.

Chris
Message 19 of 24
(1,833 Views)
thanks chris for your help ..


i managed to complete the whole program and it runs well .. i just havent checked whether the algorithm is rite... but as of now my problem has been solved. .

one thing i dont understand is .. why does my program work in comp and not in the other. with different versions of matlab. . i might be the only one who  experienced  this.

but thanks  anyways chris for  help ing me  thru my problems.
0 Kudos
Message 20 of 24
(1,808 Views)