[QUOTE=Rayjingstorm;43128818]No, that's not exactly what I mean.
Let's say you define a function:
[code]
var foo = function() { ... };
[/code]
now the identifier `foo` refers to a variable, which holds a function (I don't actually know the terminology for JS, but in most statically compile languages you would have to have a pointer to function and it would be referred to as a 'callback' because you are asking a function to 'call you back' through the function, but I digress).
If you now use the identifier `foo` (notice there are no parenthesis following it) you refer to [I]the function itself[/I], as an entity which is callable. If you then add parenthesis, i.e. `foo()`, you are in fact [I]calling[/I] the function to which `foo` refers and so are refering to whatever it returns.
In your case, both functions (`getBuyPrice` and `buy`) return [I]nothing[/I], that is to say they only have [I]side-effects[/I] and that is their purpose.
When you call async.serial([...]) you are asking it to call each of the elements of the list you pass [I]in order[/I] and do nothing with their return values. However, you are writing:
[code]
async.series([start, getBuyPrice(), buy()]);
[/code]
with the parenthesis present on the last two methods (the ones you really care about). This means the functions are called in place, [I]before[/I] async.series() even sees them. Because both functions return nothing, async.series() sees a list like this:
[code]
[[Function start], undefined, undefined]
[/code]
when, in fact, you probably intend for it to see something like:
[code]
[[Function start], [Function getBuyPrice], [Function buy]]
[/code]
I don't want to tell you the correct form of the line, because I think you should understand the error because it is a subtle but important one that will most certainly crop up again if you don't figure it out now. If you need more help, don't be afraid to ask, but I'm not going to just tell you the answer.[/QUOTE]
I'm going to re-read this in the morning when I have a clearer head
You're a star, thanks very much
You're not in too deep! You're just scratching the surface of something beautiful: program logic.
JS can only do exactly what you tell it to do; it cannot, despite its best intentions, [i]know[/i] what you [i]mean[/i] for it to do. That is, it is clear to [i]you[/i] that the call to async.serial should see the three functions as you defined them, but to Javascript the last two arguments are actually function calls, so it responds in the only way it knows how: by calling them and using their return values in their place. This is actually a blessing, because there are situations in which you might want to use the return value (for example, functions in JS can return other functions, so there are situations in which your call makes sense as-is).
In any event, I urge you to endeavor to persevere, because the end result is (almost) always worth the time spent.
[QUOTE=Tamschi;43121442]Oh, sorry, I think I skipped that part.
You probably don't need the z-value, only the x/y coords in relation to the anchor point of your transformation.
I hope the equality operator is only there to illustrate the issue, it's relatively unlikely to hit the precise starting point because of floating point errors I think.[/QUOTE]
They are only there to illustrate a point, but what I'm saying is I can't get back to the original X/Z coords using just X/Y coords.
[QUOTE=ZeekyHBomb;43128166]Both strings yes and no are not set. They're default-constructed to the empty string "".
You should do string yes = "yes" or just use "yes" instead of a variable for that purpose (probably less confusing that having to look up whether the string yes actually contains "yes").[/QUOTE]
That makes sense. I'll give that a shot. Thanks as always!
:edit:
You, sir, are goddamn brilliant! Thanks for the help. Finally i can stop messing with this damn thing and get to studying for finals. One more damn day.
I'm trying to teach myself Java at the moment. I figured a dice roller would be an easy thing to try to make first. Is there a more efficient way to make one than what I have?
[code]
import java.util.Scanner;
public class DiceRoller {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double Dice;
float LowNumber, HighNumber, result;
LowNumber = 1;
HighNumber = 6;
System.out.println("How many dice to roll? ");
Dice = input.nextDouble();
do{
total = LowInt + (int)(Math.random() * ((HighInt - LowInt) + 1));
System.out.println(result);
Dice --;
}while(Dice>0);
}
}
[/code]
You could probably use a for loop instead of a do while.
[QUOTE=Auphe;43130386]I'm trying to teach myself Java at the moment. I figured a dice roller would be an easy thing to try to make first. Is there a more efficient way to make one than what I have?
[code]
import java.util.Scanner;
public class DiceRoller {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double Dice;
float LowNumber, HighNumber, result;
LowNumber = 1;
HighNumber = 6;
System.out.println("How many dice to roll? ");
Dice = input.nextDouble();
do{
total = LowInt + (int)(Math.random() * ((HighInt - LowInt) + 1));
System.out.println(result);
Dice --;
}while(Dice>0);
}
}
[/code][/QUOTE]
Semantically `Dice` probably shouldn't be a double: `double` is a double-precision floating point number (think real numbers, like 2.4) but you can't really roll a fraction of a die. Instead you might consider using an integral type like `int`.
Also, to make it easier for others to read your code you should try to stick to conventions as far as naming and formatting is concerned. For example, types (that is, classes) are usually CamelCased, whereas variables and methods are usually lowerCamelCase. Also, spacing around curly brackets ({}) and most binary operators (+, -, <, >, etc.) is easier to read for most people.
Just suggestions, feel free to ignore them :v:
As for efficiency, you don't need to worry about that with such a simple example, and arguably you don't need to worry about that until you actually run into a performance problem.
Anyone know the best sites to study UI/UX coding? (LAMP)
[QUOTE=war_man333;43126400]Couldn't edit this post for some reason.
Wanted to add: It's 10 seconds, not 5 seconds. I just forgot!
[code]lInst.Updated -= () => dataGridView1.Invoke(dataGridViewUpdate);[/code]
What does the -= mean? The parenthesis? The =>?
Also by using the above code I'm getting
[code]Error 3 The best overloaded method match for 'System.Windows.Forms.Control.Invoke(System.Delegate, params object[])' has some invalid arguments C:\Users\Mathias\Documents\Lektier\IHA\3. Semester\Projekt\Projekt Produkt December\Projekt Produkt December\E-Detektor Interface.cs 49 36 Projekt Produkt December[/code]
and also
[code]Error 4 Argument 1: cannot convert from 'method group' to 'System.Delegate' C:\Users\Mathias\Documents\Lektier\IHA\3. Semester\Projekt\Projekt Produkt December\Projekt Produkt December\E-Detektor Interface.cs 49 57 Projekt Produkt December
[/code]
maybe I'm just way in over my head and not understanding anything at all.[/QUOTE]
Ah, sorry. I didn't test it and it seems the method signature is different for WinForms. WPF has Dispatchers that take Actions directly.
-= is the removal operator for events, you can unsubscribe using that.
[code](ParameterType parameter) => { DoSomething(); }[/code] is an anonymous method (lambda syntax), but you can shorten it to just [code]parameter => DoSomething();[/code], or [code]() => DoSomething();[/code] if there are no parameters.
Cast the first argument of Invoke to (Action), that will select the right method from the group and create an Action delegate that is compatible with Invoke.
(Method groups (plain method names) are implicitly convertible to delegates matching their signature, but not the Delegate type it seems.)
Use null for the second parameter, as you don't pass any parameters to your custom update method.
Read a bit more about lambdas, events and delegates, it's important to understand these properly. You will also be able to refactor your Logic class away if you do that.
[editline]10th December 2013[/editline]
[QUOTE=war_man333;43126920]I see the point with removing the timer.
How do you refer to an event in the data-class if I want to refer to it from a form?
Should I make some horrible class that you don't like in the logic layer that returns an event? ;)
shit my automerge[/QUOTE]
Basically you would move the event code into Data and have the Form use Data instead of Logic, as the latter seems very unnecessary at this point.
Not a class (or method, which is what these get... things are), but a property:
[code]public Data Data { get { return dInst; } } // read only
public Data Data { get; set; } // implicit, creates a backing field automatically
public Data Data { get; private set; } // implicit, readonly
public Data Data { get { return dInst; } set { dInst = value; } } // mutable[/code]
The first [I]Data[/I] is the type, the second the property name.
You can then use it like a field from the form, but ideally you'd just remove the whole Logic class and use Data instead as 90% of what it does is forwarding Data methods.
The only thing left in Logic after moving the event and exposing the Data instance would be the Listener() method, which you can pretty much put as lambda into the method starting the server thread.
[QUOTE=cartman300;43127773]Message me on steam, i added you (Cartmanium.dll), i wanted to help you with this stuff but i never happen to message you when you're online.[/QUOTE]
Haha sweet. I just accepted the invite without knowing who you were. I'll message you later tonight if that's alright.
[QUOTE=Tamschi;43132024]
Cast the first argument of Invoke to (Action), that will select the right method from the group and create an Action delegate that is compatible with Invoke.
(Method groups (plain method names) are implicitly convertible to delegates matching their signature, but not the Delegate type it seems.)
Use null for the second parameter, as you don't pass any parameters to your custom update method.
Basically you would move the event code into Data and have the Form use Data instead of Logic, as the latter seems very unnecessary at this point.
The only thing left in Logic after moving the event and exposing the Data instance would be the Listener() method, which you can pretty much put as lambda into the method starting the server thread.[/QUOTE]
Not entirely sure what you mean by 'cast the first argument of invoke to (Action).
I'm trying this;
[code]dInst.Updated += () => dataGridView1.Invoke((Action), null);[/code]
I'm pretty sure I misunderstood you or something. I'm getting:
[code]Error 3 'System.Action' is a 'type' but is used like a 'variable'[/code]
Also I removed the logic class, and I'm just using the Data class now. 2-tier architecture WOW
[QUOTE=war_man333;43132759]Haha sweet. I just accepted the invite without knowing who you were. I'll message you later tonight if that's alright.
Not entirely sure what you mean by 'cast the first argument of invoke to (Action).
I'm trying this;
[code]dInst.Updated += () => dataGridView1.Invoke((Action), null);[/code]
I'm pretty sure I misunderstood you or something. I'm getting:
[code]Error 3 'System.Action' is a 'type' but is used like a 'variable'[/code]
Also I removed the logic class, and I'm just using the Data class now. 2-tier architecture WOW[/QUOTE]
Putting a type in brackets before a value is a type cast, [code](Action)dataGridViewUpdate[/code] "casts" the method group (official name for all methods of a certain name) to the matching Action instance (by selecting the one without parameters), which is a Delegate.
Usually the cast just makes the program look differently at an instance but there are some cases like this one where a new object is constructed.
[code]dInst.Updated += () => dataGridView1.Invoke((Action)dataGridViewUpdate, null);[/code] and [code]dInst.Updated -= () => dataGridView1.Invoke((Action)dataGridViewUpdate, null);[/code] should work.
Mother of god, I'm going to fight this teacher. He wanted all of those things in individual functions, but called them methods in the prompt, so it sounded like "You can use whatever methods you want" as in whatever solutions you come up with.
Now i have to go back through and re-do this all into functions.
:edit:
Knife fight scheduled for 10:00pm in the darkest alley in town. I refuse to accept my inability to read that sentence that i have labelled confusing, and a threat to democracy and freedom everywhere.
-snip-
I have a test tomorrow and I can't figure out a problem on my study guide.
[code]
for ( int i = -1; i <= n + 2; i++ )
for ( int j = i + 1; j <= n + 5; j++ )
__________________
[/code]
How many times is the line executed?
[QUOTE=Phrozen99;43139699]I have a test tomorrow and I can't figure out a problem on my study guide.
[code]
for ( int i = -1; i <= n + 2; i++ )
for ( int j = i + 1; j <= n + 5; j++ )
__________________
[/code]
How many times is the line executed?[/QUOTE]
Did you forgot an n? If not, make sure you look at how many times the outer loop is executed, and then at how many times the inner loop is executed. By counting them, you should soon see a pattern.
(cheat: let Wolfram Alpha chew through the execution count for each n)
[QUOTE=Swebonny;43140834]Did you forgot an n? If not, make sure you look at how many times the outer loop is executed, and then at how many times the inner loop is executed. By counting them, you should soon see a pattern.
(cheat: let Wolfram Alpha chew through the execution count for each n)[/QUOTE]
I did not. Usually the answer is n + number.
[QUOTE=Phrozen99;43141045]I did not. Usually the answer is n + number.[/QUOTE]
[B]SPOILERS![/B]
Okay, first we check the outer loop for a value like n = 0. We see that the loop will run for i = -1, 0, 1, 2 so that would mean that the inner loop will be allowed to run four times. For n = 1, we see it'd mean we'd get another occasion for the inner loop to run (-1, 0, 1, 2, 3) so that's five times. You can probably figure out for yourself what n = 2 will do. Now we look at the inner loop, this depends both on what i and n is.
Let's check it for n = 0. The first i value we have is -1. This means that j initializes with 0 and runs (n + 5) + 1 times. So for the first i, it executes the line six times.
Next we have i = 0. This makes j = 1, now it is only executed five times.
We move on and get i = 1, which give j = 2, and now the line is executed four times.
For i = 2, we get j = 3, and the line executes just three times.
We have no more i values and it is done. The total number of time the line is executed is 6 + 5 + 4 + 3 = 18 times when n = 0.
You can check for yourself for higher values. for n = 1, you're going to get 3 + 4 + 5 + 6 + 7, and for n = 2 you get 3 + 4 + 5 + 6 + 7 + 8 execution.
As we see this is a fairly simple sum of the natural numbers. I assume you know that the sum of all natural numbers 1, 2, 3 ,4 ,5 ... n is n(n+1)/2.
We can't use the sum equation yet since when our n is at 0, we already got 3 + 4 + 5 + 6. So we need to alter the equation. We want make n = 0 "act" as n = 6. (since the first 6 natural numbers are 1, 2, 3, 4, 5 ,6 and is closest to the series we have).
So we assign n as n = n + 6, which gives us the equation (n+6)(n+7)/2. Now when we insert n = 0, we actually get the sum for 1 + 2 + 3 + 4 + 5 + 6. As you may have guessed the last thing we need to do is to strip off 1 and 2. So the final equation becomes:
[B]((n+6)(n+7)/2) - 3
[/B]Checking it in wolfram for n = 1 to n = 10
[IMG]http://i.imgur.com/Dk5XQNU.png[/IMG]
And checking the code.
[code]Executions: 18 n: 0
Executions: 25 n: 1
Executions: 33 n: 2
Executions: 42 n: 3
Executions: 52 n: 4
Executions: 63 n: 5
Executions: 75 n: 6
Executions: 88 n: 7
Executions: 102 n: 8
Executions: 117 n: 9
Executions: 133 n: 10[/code]
It seems to be correct.
[QUOTE=Swebonny;43142417][B]SPOILERS![/B]
Okay, first we check the outer loop for a value like n = 0. We see that the loop will run for i = -1, 0, 1, 2 so that would mean that the inner loop will be allowed to run four times. For n = 1, we see it'd mean we'd get another occasion for the inner loop to run (-1, 0, 1, 2, 3) so that's five times. You can probably figure out for yourself what n = 2 will do. Now we look at the inner loop, this depends both on what i and n is.
Let's check it for n = 0. The first i value we have is -1. This means that j initializes with 0 and runs (n + 5) + 1 times. So for the first i, it executes the line six times.
Next we have i = 0. This makes j = 1, now it is only executed five times.
We move on and get i = 1, which give j = 2, and now the line is executed four times.
For i = 2, we get j = 3, and the line executes just three times.
We have no more i values and it is done. The total number of time the line is executed is 6 + 5 + 4 + 3 = 18 times when n = 0.
You can check for yourself for higher values. for n = 1, you're going to get 3 + 4 + 5 + 6 + 7, and for n = 2 you get 3 + 4 + 5 + 6 + 7 + 8 execution.
As we see this is a fairly simple sum of the natural numbers. I assume you know that the sum of all natural numbers 1, 2, 3 ,4 ,5 ... n is n(n+1)/2.
We can't use the sum equation yet since when our n is at 0, we already got 3 + 4 + 5 + 6. So we need to alter the equation. We want make n = 0 "act" as n = 6. (since the first 6 natural numbers are 1, 2, 3, 4, 5 ,6 and is closest to the series we have).
So we assign n as n = n + 6, which gives us the equation (n+6)(n+7)/2. Now when we insert n = 0, we actually get the sum for 1 + 2 + 3 + 4 + 5 + 6. As you may have guessed the last thing we need to do is to strip off 1 and 2. So the final equation becomes:
[B]((n+6)(n+7)/2) - 3
[/B]Checking it in wolfram for n = 1 to n = 10
[IMG]http://i.imgur.com/Dk5XQNU.png[/IMG]
And checking the code.
[code]Executions: 18 n: 0
Executions: 25 n: 1
Executions: 33 n: 2
Executions: 42 n: 3
Executions: 52 n: 4
Executions: 63 n: 5
Executions: 75 n: 6
Executions: 88 n: 7
Executions: 102 n: 8
Executions: 117 n: 9
Executions: 133 n: 10[/code]
It seems to be correct.[/QUOTE]
That makes a lot more sense than what my silly professor tried to teach me. Hopefully I can do this in a couple minutes cause I have 10 other problems on the test. One thing, when I ran the code I got different numbers, 1 = 15, 2 = 22, 3 = 30, etc.
[code]
void main()
{
int n, count = 0;
cin >> n;
for(int i = 0; i < n + 2; i++)
for(int j = i + 1; j <= n + 5; j++)
count++;
cout << count;
}
[/code]
[QUOTE=Phrozen99;43142890]That makes a lot more sense than what my silly professor tried to teach me. Hopefully I can do this in a couple minutes cause I have 10 other problems on the test. One thing, when I ran the code I got different numbers, 1 = 15, 2 = 22, 3 = 30, etc.
[quote]
void main()
{
int n, count = 0;
cin >> n;
[B]for([U]int i = 0[/U]; i < n + 2; i++)[/B]
for(int j = i + 1; j <= n + 5; j++)
count++;
cout << count;
}
[/quote][/QUOTE]
I marked the typo. The code you gave me initialized i with -1.
[QUOTE=Swebonny;43142980]I marked the typo. The code you gave me initialized i with -1.[/QUOTE]
That makes more sense, I think I got everything. Thanks!
I was thinking of making an app or some sort of web service that would monitor/do something with bitcoin data (like show transactions per X or something), but the API's for most trackers arent good. How does one go about listening in on and interacting with the bitcoin network? How are sites like MTGox and Bitstamp made so they can track bitcoins and their current price?
[QUOTE=Richy19;43148079]I was thinking of making an app or some sort of web service that would monitor/do something with bitcoin data (like show transactions per X or something), but the API's for most trackers arent good. How does one go about listening in on and interacting with the bitcoin network? How are sites like MTGox and Bitstamp made so they can track bitcoins and their current price?[/QUOTE]
They probably run either on the client/a custom client or on the blob files, you have to download all transactions to use the network after all.
[editline]edit[/editline]
That doesn't apply to the current price though, the sites get that from their internal exchange rate and the offers people make on the network. You probably can't get it directly unless you use the sites. As most currencies, this one doesn't have a central exchange rate against another one.
So, more stuff to work on before end of class tonight.
My teacher wants us to read multiple lines of data (this too wasn't very clear in the prompt) from our .dat file for out blood pressure program.
I've got it working for the first person, i'm just not sure how i want to go about pulling the other 7 or so lines.
Here's the whole thing:
[code]
//identify/open variables
ifstream patient;
patient.open("C:\\patient.dat");
if (patient)
{
cerr << "Input of 'patient.dat' successful.\n\n\n\n";
}
else
{
cerr << "Input files open FAILED...";
}
//variables
string firstName, lastName;
int systolic;
int diastolic;
bool count;
char slashChar;
//read file
//test output for name
patient >> lastName >> firstName >> systolic >> slashChar >> diastolic;
cout << "Patient data for: " << lastName << ", " << firstName <<endl;
//Systolic readings
if (systolic >= 160)
cout << "\nSystolic Blood Pressure of " << systolic << " is Stage 2-Hypertensive. \n\n";
else if (systolic >= 140)
cout << "\nSystolic Blood Pressure of " << systolic << " is Stage 1-Hypertensive.\n\n";
else if (systolic >= 120)
cout << "\nSystolic Blood Pressure of " << systolic << " is Pre-hypertensive.\n\n";
else if (systolic <= 119)
cout << "\nSystolic Blood Pressure of " << systolic << " is Normal.\n\n";
//Diastolic Reading
if (diastolic >= 100)
cout << "Diastolic Blood Pressure of " << diastolic << " is Stage 2-Hypertensive. \n\n";
else if (diastolic >= 90)
cout << "Diastolic Blood Pressure of " << diastolic << " is Stage 1-Hypertensive.\n\n";
else if (diastolic >= 80)
cout << "Diastolic Blood Pressure of " << diastolic << " is Pre-hypertensive.\n\n";
else if (diastolic <= 79)
cout << "Diastolic Blood Pressure of " << diastolic << " is Normal.\n\n";
patient.close();
Pause();
//system("PAUSE");
return(0);
}
[/code]
So, i was thinking i needed to execute the input section multiple times. Would this print it to the screen once for each time it runs, or would i have to go through and loop the calculation section as well?
I was thinking of using a while loop to do something like
[code]
while(something_i_cant_think_of){
patient >> lastName >> firstName >> systolic >> slashChar >> diastolic;
}
[/code]
Would that go through the input section until it didn't run into anything to pull anymore? I thought about trying a count, but i didn't want to make anything that would limit it if there were different numbers of patients.
Oh, here's what the patient data looks like in patient.dat.
[code]
Doe John 170/43
James Lebron 180/60
Costas Bob 140/30
[/code]
Something like that.
[editline]11th December 2013[/editline]
Or, a thought:
Would i need to put everything from above the input line to after the last calculations in a loop?
Right, here's a picture of a signal (left) and fast fourier transform of it (right).
[img]http://i.imgur.com/fObL6ce.png[/img]
I'm trying to get the frequency of the peak, which is related to the array index number which holds the highest value.
The code is super simple, but isn't working...
[code] int mIndex;
double lMax;
mIndex = 0;
lMax = power[0];
for (int i = 0; i < N / 2; i++)
{
//find maximum array value index
if (power[i] > lMax)
{
mIndex = i;
lMax = power[i];
}
}[/code]
Where N/2 is the number of samples. It [i]always[/i] gives mIndex of 0, even though I have checked the power[0] and it's only 3.4 or so, when the peak is in the hundreds as you can see. Have I done something super stupid?
Welp, i got that sorted out. Now i just have to find a way to create a loop that determines if characters are larger than another.
I guess i'm supposed to take A and say it's larger than a.
Using c# charts, how do I change the x axis "values"? at the moment, using:
[code] for (int i = 0; i < N; i++)
{
//plot it
chart1.Series[0].Points.Add(samples[i]);
}[/code]
To plot the contents of samples[], it plots each index of samples with an x-value of i, so 1,2,3... whereas I need them plotted at decimal values, e.g samples[0] at 0, samples[1] at 0.15, samples[2] at 0.3 etc.
Thanks for any help! :smile:
Having issues adding stuff to this Queue. See the comments.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;
namespace Server
{
class ConnectionHandler
{
private Queue<ConnectionMessage> messageQueue = new Queue<ConnectionMessage>();
public void Start()
{
Server.OnUpdate += () =>
{
if (messageQueue.Count >= 1)
{
//Handle client connection.
ConnectionMessage msg = messageQueue.Dequeue();
var ply = new Player(msg.Message[1]);
}
};
}
public void AddMessage(string[] str, NetConnection con)
{
messageQueue.Enqueue(new ConnectionMessage(str, con)); //While debugging here str and con are not null.
} //Right after it is Enqueued it is null in the messageQueue.
public class ConnectionMessage
{
public string[] Message;
public NetConnection Connection;
public ConnectionMessage(string[] Message, NetConnection Connection)
{
Console.WriteLine(Message[0]);
}
}
}
}
[/code]
Any help would be much appreciated, thanks.
[editline]12th December 2013[/editline]
Talk about dumb mistakes, I forgot to assign the variables in my ConnectionMessage constructor.
I'll leave it up so everyone can laugh at my incompetence.
[QUOTE=reevezy67;43156635]-code-[/QUOTE]
This doesn't look thread safe, unless you're running it all on the same dispatcher you need synchronization.
[QUOTE=Tamschi;43157318]This doesn't look thread safe, unless you're running it all on the same dispatcher you need synchronization.[/QUOTE]
I'm aware, for the moment it is just the one dispatcher. I don't expect that to change, but it won't be hard to fix if need be, I'll just throw in a ConcurrentQueue.
[QUOTE=chaz13;43151033]Right, here's a picture of a signal (left) and fast fourier transform of it (right).
[img]http://i.imgur.com/fObL6ce.png[/img]
I'm trying to get the frequency of the peak, which is related to the array index number which holds the highest value.
The code is super simple, but isn't working...
[code] int mIndex;
double lMax;
mIndex = 0;
lMax = power[0];
for (int i = 0; i < N / 2; i++)
{
//find maximum array value index
if (power[i] > lMax)
{
mIndex = i;
lMax = power[i];
}
}[/code]
Where N/2 is the number of samples. It [i]always[/i] gives mIndex of 0, even though I have checked the power[0] and it's only 3.4 or so, when the peak is in the hundreds as you can see. Have I done something super stupid?[/QUOTE]
I tried your code and it worked fine. I think it may be either the data in your array that somehow messes it up... What happens if you replace N/2 with a random number withing your bounds. I copypasted your code, only difference is the data and the loop condition.
[code] double[] sample = new double[10];
sample[0] = 3.1;
sample[1] = 3.4;
sample[2] = 5.4;
sample[3] = 15.4;
sample[4] = 55.4;
sample[5] = 64.4;
sample[6] = 31.4;
sample[7] = 1351.4;
int mIndex = 0;
double lMax = sample[0];
for (int i = 0; i < 8; i++)
{
//find maximum array value index
if (sample[i] > lMax)
{
mIndex = i;
lMax = sample[i];
}
}
Console.Write("Max index = " + mIndex);[/code]
Sorry, you need to Log In to post a reply to this thread.