LOOPING
LOOPING
(OP)
I need some assistance with looping. Specifically I would like to interrogate an array to list the values in it and number of occurrences of each one. Say my array was (0.980 0.982 0.971 0.976 0.977 0.976 0.976 0.975 0.969 0.968), I would like to get a list of the form:-
0.968 1
0.969 1
0.971 1
0.975 1
0.976 3
0.977 1
0.980 1
0.982 1
The problem for me is that I am having difficulty with understanding Mathcad looping; my Mathcad knowledge is entirely self-taught.
Thanks in anticipation.
0.968 1
0.969 1
0.971 1
0.975 1
0.976 3
0.977 1
0.980 1
0.982 1
The problem for me is that I am having difficulty with understanding Mathcad looping; my Mathcad knowledge is entirely self-taught.
Thanks in anticipation.





RE: LOOPING
Cheers
Greg Locock
SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: LOOPING
RE: LOOPING
But, creating the interv vector automatically is going to be tricky without loops. And the only way I've thought of creating it obviates the need to use hist...
here's what i've got in pseudocode as i don't have Mathcad with loops. untested. Things may need initialising.
sx:=sort(x)
binptr:=0
for xptr:0..(length(x)-1)
if sx[xptr=interv[binptr
n[binptr:=1+n[binptr
else
binptr:=binptr+1
interv[binptr:=sx[xptr
n[binptr:=1
endif
endfor
This creates an entry in interv for each unique value in x, and then counts the number of occurences of each value.
There is a bit of ugliness for the first bin. It is valid if there is a zero present in x, not otherwsie.
Cheers
Greg Locock
SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: LOOPING
RE: LOOPING
RE: LOOPING
Cheers
Greg Locock
SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: LOOPING
Thanks for taking the time to help. I now have a solution.
Regards,
Louis