New with MathCad
New with MathCad
(OP)
Guys, I could use a little help. I am trying to learn MathCad and have come up on something I need a little help with. I have a matrix as shown below.
A = 1 1
0 0
0 0
I need to coun the number of "1"s and the number of "0"s. I set variables named NumFree and NumRest to zero. If A i,j is one, then I want to add 1 to NumRest. If A i,j is zero, I want to add 1 to NumFree.
Any help would be greatly appreciated.
A = 1 1
0 0
0 0
I need to coun the number of "1"s and the number of "0"s. I set variables named NumFree and NumRest to zero. If A i,j is one, then I want to add 1 to NumRest. If A i,j is zero, I want to add 1 to NumFree.
Any help would be greatly appreciated.





RE: New with MathCad
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: New with MathCad
NumFree:=sum(vectorize(A=0))
NumRest:=rows(A)*cols(A)-NumFree
where
sum represents the vector sum operator ([ctrl]4)
vectorize(A=0) represents the vectorize operator ([ctrl]-) applied to the expression A=0, where = is the boolean equals ([ctrl]=)
RE: New with MathCad
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: New with MathCad
0 1
0 2
Has too 0s, and one 1
your method would give the wrong answer
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: New with MathCad
I'm guessing from the variable names that NumFree is meant to count something that is available, in the sense of 'not taken' (or doesn't cost anything!) and zero is the measure of that state. NumRest I took to be 'The rest of them' in which case, what I propose should work - count the zeros (NumFree) and take that number away from the total number of elements to get the Rest.
However, you're quite right; without a full quantification it is simply guess work.
RE: New with MathCad
Thanks again
RE: New with MathCad