From: Gumah on 20 May 2010 23:58 hi all lets say we have T3=[D1 D2 D3 D4 D5 D6 ]; switch (C) case (D1) fprintf( '. A\n' ); case (D2) fprintf( '. B\n' ); case (D3) fprintf( '. C \n' ); case (D4) fprintf( '. D \n' ); End if we call this code by matlab function many times.. how can we count how many time it will print out A and how many time it will print B and so on??
From: Walter Roberson on 21 May 2010 00:23 Gumah wrote: > lets say we have > T3=[D1 D2 D3 D4 D5 D6 ]; > switch (C) > case (D1) > fprintf( '. A\n' ); > case (D2) > fprintf( '. B\n' ); > case (D3) > fprintf( '. C \n' ); > case (D4) > fprintf( '. D \n' ); > End > if we call this code by matlab function many times.. how can we count > how many time it will print out A and how many time it will print B > and so on?? If Cvec is a vector containing all of the different C that the function will be invoked with, then Counts = histc(CVec, sort(T3)); Note, though, that Counts will be in sorted order of T3, not in the original order. Study the sort() command to figure out how to get back to the original order.
From: Gumah on 21 May 2010 01:02 On May 21, 12:23 pm, Walter Roberson <rober...(a)hushmail.com> wrote: > Gumah wrote: > > lets say we have > > T3=[D1 D2 D3 D4 D5 D6 ]; > > switch (C) > > case (D1) > > fprintf( '. A\n' ); > > case (D2) > > fprintf( '. B\n' ); > > case (D3) > > fprintf( '. C \n' ); > > case (D4) > > fprintf( '. D \n' ); > > End > > if we call this code by matlab function many times.. how can we count > > how many time it will print out A and how many time it will print B > > and so on?? > > If Cvec is a vector containing all of the different C that the function > will be invoked with, then > > Counts = histc(CVec, sort(T3)); > > Note, though, that Counts will be in sorted order of T3, not in the > original order. Study the sort() command to figure out how to get back > to the original order.- Hide quoted text - > > - Show quoted text - Thanks for your replay... This code will find the minimum of T3.. the minimum =D1 it will print out A.. my question.. if this code was called by a function many times.. each time D1,D2,... are different.. so the minimum will be different each time.. so it will print out different letter.. How can accout how many times it will print out A and how many times it will print out B and so on T3=[D1 D2 D3 D4 D5 D6 ]; C=min(T); switch (C) case (D1) fprintf( '. A\n' ); case (D2) fprintf( '. B\n' ); case (D3) fprintf( '. C \n' ); case (D4) fprintf( '. D \n' ); End
From: Walter Roberson on 21 May 2010 01:37 Gumah wrote: > This code will find the minimum of T3.. the minimum =D1 it will print > out A.. my question.. if this code was called by a function many > times.. each time D1,D2,... are different.. so the minimum will be > different each time.. so it will print out different letter.. How can > accout how many times it will print out A and how many times it will > print out B and so on > > T3=[D1 D2 D3 D4 D5 D6 ]; > C=min(T); > switch (C) > case (D1) > fprintf( '. A\n' ); > case (D2) > fprintf( '. B\n' ); > case (D3) > fprintf( '. C \n' ); > case (D4) > fprintf( '. D \n' ); > End Are you trying to figure out how many times it _would_ print out those letters, but without executing the code and counting? Or are you trying to change the code so that it keeps track of the number of times each one has been printed, and then access those counts at the end? If you are trying to count the number of times actually printed, you will either need to make the function a nested function, or you will need to use a 'global' variable. If you are trying to predict the number of times it _would_ print, but without actually executing the code, then you need to be clearer as to what information is available. For example, if it is to be called N times, then do you have an N x 6 array of all of the values it would be called with?
From: Gumah on 21 May 2010 06:11
On May 21, 1:37 pm, Walter Roberson <rober...(a)hushmail.com> wrote: > Gumah wrote: > > This code will find the minimum of T3.. the minimum =D1 it will print > > out A.. my question.. if this code was called by a function many > > times.. each time D1,D2,... are different.. so the minimum will be > > different each time.. so it will print out different letter.. How can > > accout how many times it will print out A and how many times it will > > print out B and so on > > > T3=[D1 D2 D3 D4 D5 D6 ]; > > C=min(T); > > switch (C) > > case (D1) > > fprintf( '. A\n' ); > > case (D2) > > fprintf( '. B\n' ); > > case (D3) > > fprintf( '. C \n' ); > > case (D4) > > fprintf( '. D \n' ); > > End > > Are you trying to figure out how many times it _would_ print out those > letters, but without executing the code and counting? Or are you trying > to change the code so that it keeps track of the number of times each > one has been printed, and then access those counts at the end? > > If you are trying to count the number of times actually printed, you > will either need to make the function a nested function, or you will > need to use a 'global' variable. > > If you are trying to predict the number of times it _would_ print, but > without actually executing the code, then you need to be clearer as to > what information is available. For example, if it is to be called N > times, then do you have an N x 6 array of all of the values it would be > called with?- Hide quoted text - > > - Show quoted text - I am trying to change the code so that it keeps track of the number of times each one has been printed, and then access those counts at the end.. |