03-31-2009 05:05 AM
So I have a 2D data set (at the moment it is a set of random numbers) that I have obtained from histogram binning of 100,000 data points into 1000 bins. One column (column 0) are the binned intensity (I) values I am after and the other column (column 1) is the number of these binned intensity values that have been binned (ie # of observations, N)
Now what I need to do now is to go through the entire array (ie the 1000 bins) and find the maximum product of N*I, where these values of N and I are now Nm and Im respectively (so the maximum product is Nm*Im).
What I have done is to separate the two columns into separate arrays, one for intensity and one for number of observations. Now the best way that I could think to find the maximum product is use the Mathscript Node. I have a Fortran code that has previously done this, this is shown here;
nximax=0
do 140 ints=1,1000
if(num(ints)*ints.gt.nximax)then
nummost=num(ints)
intmost=ints
nximax=nummost*intmost
end if
140 continue
(note that in my node code I have changed - nximax to NmIm, nummost to Nm, intmost to Im, num(inst) to N and inst to I)
But I find that when I run the code as I have it, it doesn't work. I am not sure that my prepration of the data prior to going into the node is correct (I tried putting it in a For Loop but it didn't like that (it said the array was wired wrong, and probably most importantly I don't think I have made the conversion from the Fortran code (as detailed above) to an appropriate mathscript syntax.
So the help I am after here is a double check on my wiring prior to the data entering the mathscript node (especially given that I want to get the product of the Intensity and observation number for each bin) and how to correctly convert the fortran code to mathscript code so that it does the same thing.
Any help would be appreciated.
I am using LV 8.6.1
I have attached thevi of interest: PE profile #1.vi
and some random data I have put together.
Thanks,
Scott
Solved! Go to Solution.
03-31-2009 08:19 AM
Labview has a max/min function; its in the math functions group.
03-31-2009 09:23 AM
03-31-2009 04:33 PM - edited 03-31-2009 04:39 PM
For programmers coming from other languages into LabVIEW, one of the hardest things to master is ALL THE CRAP YOU DON'T HAVE TO DO ANYMORE.
It's not clear from your description whether you need the PAIR that produces the largest product, or the INDIVIDUALS that produce the largest product.
So here's both ways.
In the upper part, you multiply A x B, and pick out the max of the result.
In the lower part you pick out the max of the two sources, and multiply them.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-31-2009 06:28 PM - edited 03-31-2009 06:30 PM
@Mr6dof - I was aware of Labview having a Max/min array function but not one in the math functions group (and from a quick check I couldn't see it).
@GrantM - thanks that seems to work perfectly. I appreciate it. I will try to let you know how it goes when I eventually get some real (ie experimental data) going through.
@CoastalMaineBird - My issue is that I don't have any programming experience other than what I am getting at the moment using Labview. But I do take your point about not always having to do stuff the same way. Hence my question of how to translate the fortran code to mathscript code (ie I am not exactly familiar with either). Sorry I wasn't clear about what exactly I was after here, it was the the pair the produces the larget product. And from that I need the value of the product and also the the N and I values that gave rise to that value (ie Nm and Im). I had actually considered your top approach, but I wasn't enitrley sure of how to then take the index of the max product and extract from that the N and I values at that index value (is there actually an easy way to do that). Hence me then going onto the mathscript node stuff where I thought it might be possible to find a way to mimic the fortan code there. But thanks for taking the time to give me some feedback and it is always good to come across different approaches, especially in programming. You never know when it might come in useful
Somewhat off topic here - just thought I would ask, how do you edit your posts? --> just realised you can edit a post yuo just made, but not an older post (I had always been trying it with older posts)
Thanks again,
Scott
03-31-2009 08:14 PM
Cool, just be aware that there are some VERY powerful tools under the LabVIEW hood, and don't limit yourself to the same ways of thinking as are in other languages. The fact that an array can be multiplied by an array is just such an idea.
how do you edit your posts? --> just realised you can edit a post yuo just made, but not an older post (I had always been trying it with older posts)
Yeah, you can only edit your own post, and only if it's the LAST post. When somebody else comes along, your post gets written in ink.
You display a picture in-line by first submitting the pic as an attachment. That gives you the address on NI servers where it resides. Then you edit the post to include an IMG SRC tag, with the address you just discovered.
Or you edit it to fix the stoopid typos when yuo fat-fingered the keebored. ;->
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-31-2009 08:59 PM
CoastalMaineBird wrote:how do you edit your posts? --> just realised you can edit a post yuo just made, but not an older post (I had always been trying it with older posts)
Yeah, you can only edit your own post, and only if it's the LAST post. When somebody else comes along, your post gets written in ink.
No. You can only edit a post within 10 minutes of when you first submitted it. If you wait until after 10 minutes, the Edit option disappears from the option menu. If you start editing within the 10 minute window, but it takes you too long and you are outside the 10 minutes when you submit your edited post, you will get a timeout error message.
You are able to edit your posts even if someone has already submitted a message immediately after yours. You can see examples of this occurring in the middle of the day when the forums are busy and several people are all replying to the same thread at once.
04-01-2009 08:17 AM
You can only edit a post within 10 minutes of when you first submitted it.
I stand corrected. I guess when I noticed it, the 10 minute period, and the next post happened about the same time, and I guessed wrongly.
Blog for (mostly LabVIEW) programmers: Tips And Tricks