08-07-2013 03:39 PM
All,
I searched all 12 pages of this forum and could not find this solution. If this is a repeat I am sincerely sorry.
I am attempting to use matlab's 'eval' and 'num2str' commands in the MathScript Module. For instance:
for ii = 1:10;
eval(['w' num2str(ii) '= ii;']);
end
The issue is that 1) it says that it will slow down the program (I get that) and 2) it does not seem to be running the whole script. I am looking for certain 'w' matrices/vectors/scalars as the output.
Also, as part of the script I have other variables that I would like to use as an output. When I try to add them, labview states that: "You must define this variable in the script and then set it's data type". I am getting the output variable by: right click --> add output --> click on variable. Even variables that are not used in the script that I want to pass on are giving the same error.
For instance:
input variables = x y z
for ii = 1:x
eval(['y' num2str(ii) '= ii;']);
end
output variables (through above method) will show all three but even with just passing 'z' through I get that same error.
This error does not appear when I do basic math in the node and pass on unused variables.
Any ideas, suggestions, solutions would be appreciated. If needed I can post some of my code; however, I have given the pertinent information above.
Best,
Corbin Wilhelmi
Solved! Go to Solution.
08-08-2013 02:20 AM
Hi,
Your first script is much similar as the example code in online help of eval. This script will generate 10 scalar variables, w1 to w10. You can confirm that by running the script in MathScript Window.
I am not very clear of your second problem. Could you please post your code?
08-08-2013 11:57 AM
TTRR;
Thank you for your reply. The full code is around 106 lines and loaded below as an attachment. Input X (train_data, attached) is a 800 x 2 matrix with four different gaussian distributions of 200 x 2 size. Input D (desired_data2, attached) is a 800 x 1 vector of desired outputs ranging from 1-4 and corresponds to the distributions in X. Assume the numbers for the following variables: n = .1, m = .01, smse = .055.
I also tried my example, the one you said was similar to the online help, and it will not allow me to export the variables w1:10. I tried to add it as an undetected variable and it will still give me the same error.
Hope that this helps you understand my problem a little bit better. I greatly appreciate your patience and advice as I am proficient in matlab but need the speed of labview for what I am working on.
Cheers,
Corbin
08-08-2013 12:01 PM
It would probably help if I attached the rest of the information. Apologies as I had to save them in a format that I could upload.
08-08-2013 04:09 PM
There is an error in line 51 of the code, it should read:
eval(['net' num2str(ii) '= ones(P,L(ii+1)+1);']); % the second 'i' after L was not there in the previous code.
This; however, does not fix my problem.
08-08-2013 10:07 PM
Corbin,
What is the end goal when using the eval function? Are you expecting the data to occupy an array?
Which part of your eval function are you not seeing executing? Can you post what the results you're seeing from the above snippet of code and what results you are expecting. It may be easier to use the MathScript window which you can launch from the Tools Menu in LabVIEW. This will show you all the variables created with your code.
08-08-2013 10:58 PM
Hi,
I run your script in LabVIEW 2013 and does not see any error. The while loop runs 2000 iterations and returns mse as 0.0789. Which version of LabVIEW do you use?
By the way, I would suggest not to use eval in loop. As the help says, eval will slow down the program.
08-09-2013 01:49 PM
Kyle,
What I am trying to do is create an artifical neural network using my own code. I have been using the MathScript Node and with your suggestion looking at the Window now. Ideally I would like to use cells like you can in matlab, it will simplify the code and I can avoid the 'eval' and 'num2str' commands. However; as I have read, these are not usable in MathScript. In essence, I need to have the code run while outputing into the block diagram all of the variables that it creates.
ttrr,
What would you suggest instead of using 'eval'?
Thanks for the help guys,
Corbin
08-09-2013 02:41 PM
Here is a different way of putting the question that maybe you guys can help me with since it is more just wiring for loops but I am struggling to do it correct.
Let's say that an end user wants 4 matrices.
Matrix 1 is 2 x Number of rows in matrix 2 (in our example 11)
Matrix 2 is 11 x Number of rows in matrix 3 (in our example 10)
Matrix 3 is 10 x Number of rows in matrix 4 (in our example 4)
Matrix 4 is 4 x 1 Column vector
If I could do something like this I could get rid of the 'eval' commands and make it run a whole lot faster. The number of matrices would be user dependent as would the number of rows in matrix 2 through matrix n-1. The matrices would be initialized with random numbers from the generator. A .jpg or sample .vi would be amazing.
Sorry for my questions guys. I am starting to get frustrated as I do not use labview that much (use a lot more matlab).
08-09-2013 02:43 PM - edited 08-09-2013 02:44 PM
Corbin,
I would suggest passing in an array of a specific size that meets your requirements and then modifing the values. If the number of results changes then make the array larger than you expect to need and provide some size values as an output.
Kyle Hartley