Hello Huihui,
There are many problems here. The 1D array representing the phase exists in LabVIEW. If you were to index this array, the valid indices are 0-1023 as you mention. However, there are 1024 elements. When you wire this into a MathScript node, there are still 1024 elements, but now you index them from 1-1024. Index 0 in LabVIEW will return the same element as index 1 in MathScript. I am not sure about the out of bounds error if you have replaced index k-1 with k. Since the example you posted is now using the formula node, let's investigate that instead.
The formula node uses a C-like syntax. In LabVIEW MathScript, you generally can execute scripts written in the MATLAB® language syntax. However, the MathScript engine executes the scripts, and the MathScript engine does not support some functions that the MATLAB software supports. It looks like you are mixing the syntax between the two nodes. Try viewing the LabVIEW help topic "Formula Node Syntax." To view it, go to "Help >> Search the LabVIEW Help..." Click on the index tab and type "formula." Under the "Formula Nodes" list, double-click "syntax."
Some things to note in the formula node:
- Indexing begins at index 0, as with LabVIEW and C.
- You need to declare variables to be an array using C-like syntax (e.g. int32 a[3][4];)
- Array indexing uses square brackets in C-like syntax, not parentheses.
- Multi-dimensional arrays are indexed using several sets of square brackets in C-like syntax, not separated by commas within parentheses.
After fixing these things, I don't see any other problems with the script you posted.
MATLAB® is a registered trademark of The MathWorks, Inc.
Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments