Working with a column of a 2D wave
Sandbo
I tried to create a 2D waves, Data, with 100 rows and 10 columns, by make/n=(100,10) Data
In my routine, I want to write to each column by passing "it" to a function, like Capture(Data[][i]), which write to a vector Data[][i]
but it doesn't seem to work this way as it does not accept [i] inside the parentheses.
Is there a way, without using a container vector Data_i, to perform the above?
I tried to create the container vector but it vastly (10 times) slow down the whole routine.
Appreciated if you can give me a hint if I was missing something.
Make/O/N=(100,10) data
Variable i
for(i = 0; i < 10; i += 1)
Capture(i)
endfor
End
Function Capture(i)
Variable i
WAVE/Z data
data[][i] = i + gnoise(0.1) // whatever you want to do to the column
End
Depending on what you want to do to the column, you could just work in the first function rather than pass anything, i.e. if it's just as simple as this, the second function is not required.
August 28, 2017 at 01:53 pm - Permalink
Wave Data
Variable col
... do something with Data[][col]
end
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 28, 2017 at 01:52 pm - Permalink
The biggest reason I was trying to do this was that, the Capture(wave) function is actually an XOP written in C.
It use the wave passed to it as a wave handle, where in the C function data is written onto the wave I give it.
That's why I could not really modify the Capture() in Igor like the mentioned (which I definitely wanted to).
My current (and extremely slow) implementation is to convert each column explicitly to 1D vector wave, write, then put it back into the 2D wave.
A possible solution (which I will have to check) is to pass the 2D wave directly to C and perform it there, but I am not sure how difficult is it to handle a 2D Igor wave in C?
Do you know if it will be a 2D array of some kinds?
Thanks.
August 28, 2017 at 03:15 pm - Permalink
A 2D wave is an array in "column-major" order (see https://en.wikipedia.org/wiki/Row-_and_column-major_order). This means that all of the elements of one column are contiguous in memory, followed by all of the elements of the next column, and so on.
This is explained in Chapter 7 of the XOP Toolkit manual under "Organization of Numeric Data in Memory".
August 28, 2017 at 05:11 pm - Permalink