Message Boards Message Boards

[✓] Create a loop to compute the minimum?

GROUPS:

I have a long data (795,000 rows). For every 5000 rows I need the minimum and the position of this minimum. Then I will get 159 minima with their positions. I tried to create a loop to calculate these minima, but I didn't find a correct way. If my data is dd What should I do to correct this

mini[i_] := Min[dd[[i ;; i + 5000]]]
pos[i_] := Position[dd, mini[[i]]]

minima = {}
For[i = 1, i <= Length[dd], i + 5000,
 AppendTo[minima, {mini[[i]], pos[[i]]}]]

Thanks in advance.

POSTED BY: Ghady Almufleh
Answer
1 month ago

.

dd = {Insert Your 795000 Numbers Here};
part = -1;
Map[(part++; pos=Ordering[#,1]; Flatten[{#[[pos]], part*5000+pos}])&, Partition[dd,5000]]
POSTED BY: Bill Simpson
Answer
1 month ago

Thank you for your help! I tried to use your command, but my data has specific numbers. It is the result of another code that computes the differential cross sections, so do you think I can use RandomReal.? I should get stable values of the minima.

POSTED BY: Ghady Almufleh
Answer
1 month ago

I really appreciate it. I got what I need.Thanks a lot!

POSTED BY: Ghady Almufleh
Answer
1 month ago

Group Abstract Group Abstract