Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. dynamic array use?

dynamic array use?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gentleguy
    wrote on last edited by
    #1

    dear all int * nColumnCounts1 nColumnCounts2 nColumnCounts3 nColumnCounts4 nColumnCounts5 =new int[constant]; the following is dynamic arrays, and nColumnCounts1,nColumnCounts2,nColumnCounts3 were calculated already correctly, now i would like to calculate nColumnCounts4,nColumnCounts5 as per following formular. is this right way? nColumnCounts4[m]=abs(nColumnCounts1[m]-nColumnCounts2[m]); nColumnCounts5[m]=abs(nColumnCounts2[m]-nColumnCounts3[m]); and then i can get new nColumnCounts4,5. however i couldn't correct result. anyone has suggestion to me, thanks a lot

    gentleguy

    CPalliniC 1 Reply Last reply
    0
    • G gentleguy

      dear all int * nColumnCounts1 nColumnCounts2 nColumnCounts3 nColumnCounts4 nColumnCounts5 =new int[constant]; the following is dynamic arrays, and nColumnCounts1,nColumnCounts2,nColumnCounts3 were calculated already correctly, now i would like to calculate nColumnCounts4,nColumnCounts5 as per following formular. is this right way? nColumnCounts4[m]=abs(nColumnCounts1[m]-nColumnCounts2[m]); nColumnCounts5[m]=abs(nColumnCounts2[m]-nColumnCounts3[m]); and then i can get new nColumnCounts4,5. however i couldn't correct result. anyone has suggestion to me, thanks a lot

      gentleguy

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Hint 1: Post the actual code. Hint 2: Use the code block button to surround code snippets with <pre> tags. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      G 1 Reply Last reply
      0
      • CPalliniC CPallini

        Hint 1: Post the actual code. Hint 2: Use the code block button to surround code snippets with <pre> tags. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        G Offline
        G Offline
        gentleguy
        wrote on last edited by
        #3

        thanks for your reminder. this is actual code. i would like to get nColumnCounts4,nColumnCounts5. is this code right? however i just can get same big value. couldn't get what i want. where is problem, thanks. nColumnCounts1,nColumnCounts2,and nColumnCounts3 are all right, i checked already.

        int a = _iBoundheight%3; // remainder

        for(iY=0;iY<(a+(static\_cast<int>(\_iBoundheight/3)));iY++)
        {
        	for (iX=\_iBoundx;iX<\_iBoundwidth;iX++)
        	{
        		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
        		{			
        			nColumnCounts1\[iX\]++;  
        
        		}
        	}
        }
        
        for(iY=(a+(static\_cast<int>(\_iBoundheight/3)));iY<(a+2\*(static\_cast<int>(\_iBoundheight/3)));iY++)
        {
        	for(iX=\_iBoundx; iX<\_iBoundwidth; iX++)
        	{
        		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
        		{			
        			nColumnCounts2\[iX\]++;  
        
        		}
        	}		
        }
        
        for(iY=(a+2\*(static\_cast<int>(\_iBoundheight/3)));iY<\_iBoundheight;iY++)
        {
        	for(iX=\_iBoundx; iX<\_iBoundwidth; iX++)
        	{
        		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
        		{	
        			nColumnCounts3\[iX\]++;  
        
        		}
        	}		
        }
        
        
        // Average
        int a1,a2,a4,a5,s1,s2,s3,r1,r2,r3,av1,av2;
        a4=a5=0;
        s1=s2=0;
        r1=r2=0;
        av1=av2=0;
        	
        // Standard deviation
        for (int m=0;m<\_iBoundwidth;m++)
        {
        	nColumnCounts4\[m\]=abs(nColumnCounts1\[m\]-nColumnCounts2\[m\]);
                    nColumnCounts5\[m\]=abs(nColumnCounts2\[m\]-nColumnCounts3\[m\]);
        	a4=a4+nColumnCounts4\[m\];
        	a5=a5+nColumnCounts5\[m\];
        }
        	
        av1=a4/\_iBoundwidth;
        av2=a5/\_iBoundwidth;
        
        for (int m2=0;m2<\_iBoundwidth;m2++)
        {
        	s1=s1+pow(nColumnCounts4\[m2\]-av1,2.0);
                    s2=s2+pow(nColumnCounts5\[m2\]-av2,2.0);
        }
        
        \_fFeature\[0\] = sqrt(s1/\_iBoundwidth);
        \_fFeature\[1\] = sqrt(s2/\_iBoundwidth);
        
        	
        delete\[\] ImgArray;
        delete\[\] nColumnCounts1;
        delete\[\] nColumnCounts2;
        delete\[\] nColumnCounts3;
        delete\[\] nColumnCounts;
        delete\[\] nColumnCounts4;
        delete\[\] nColumnCounts5;
        
        return true;
        

        }

        gentleguy

        CPalliniC 1 Reply Last reply
        0
        • G gentleguy

          thanks for your reminder. this is actual code. i would like to get nColumnCounts4,nColumnCounts5. is this code right? however i just can get same big value. couldn't get what i want. where is problem, thanks. nColumnCounts1,nColumnCounts2,and nColumnCounts3 are all right, i checked already.

          int a = _iBoundheight%3; // remainder

          for(iY=0;iY<(a+(static\_cast<int>(\_iBoundheight/3)));iY++)
          {
          	for (iX=\_iBoundx;iX<\_iBoundwidth;iX++)
          	{
          		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
          		{			
          			nColumnCounts1\[iX\]++;  
          
          		}
          	}
          }
          
          for(iY=(a+(static\_cast<int>(\_iBoundheight/3)));iY<(a+2\*(static\_cast<int>(\_iBoundheight/3)));iY++)
          {
          	for(iX=\_iBoundx; iX<\_iBoundwidth; iX++)
          	{
          		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
          		{			
          			nColumnCounts2\[iX\]++;  
          
          		}
          	}		
          }
          
          for(iY=(a+2\*(static\_cast<int>(\_iBoundheight/3)));iY<\_iBoundheight;iY++)
          {
          	for(iX=\_iBoundx; iX<\_iBoundwidth; iX++)
          	{
          		if (ImgArray\[iX+iY\*\_iBoundwidth\] == 255)          
          		{	
          			nColumnCounts3\[iX\]++;  
          
          		}
          	}		
          }
          
          
          // Average
          int a1,a2,a4,a5,s1,s2,s3,r1,r2,r3,av1,av2;
          a4=a5=0;
          s1=s2=0;
          r1=r2=0;
          av1=av2=0;
          	
          // Standard deviation
          for (int m=0;m<\_iBoundwidth;m++)
          {
          	nColumnCounts4\[m\]=abs(nColumnCounts1\[m\]-nColumnCounts2\[m\]);
                      nColumnCounts5\[m\]=abs(nColumnCounts2\[m\]-nColumnCounts3\[m\]);
          	a4=a4+nColumnCounts4\[m\];
          	a5=a5+nColumnCounts5\[m\];
          }
          	
          av1=a4/\_iBoundwidth;
          av2=a5/\_iBoundwidth;
          
          for (int m2=0;m2<\_iBoundwidth;m2++)
          {
          	s1=s1+pow(nColumnCounts4\[m2\]-av1,2.0);
                      s2=s2+pow(nColumnCounts5\[m2\]-av2,2.0);
          }
          
          \_fFeature\[0\] = sqrt(s1/\_iBoundwidth);
          \_fFeature\[1\] = sqrt(s2/\_iBoundwidth);
          
          	
          delete\[\] ImgArray;
          delete\[\] nColumnCounts1;
          delete\[\] nColumnCounts2;
          delete\[\] nColumnCounts3;
          delete\[\] nColumnCounts;
          delete\[\] nColumnCounts4;
          delete\[\] nColumnCounts5;
          
          return true;
          

          }

          gentleguy

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          gentleguy wrote:

          av1=a4/_iBoundwidth; av2=a5/_iBoundwidth;

          av1, av2 should be declared double (or float). Then change the above expression to:

          av1 = (double)a4 / _iBoundwidth;
          av2 = (double)a5 / _iBoundwidth;

          gentleguy wrote:

          s1=s1+pow(nColumnCounts4[m2]-av1,2.0); s2=s2+pow(nColumnCounts5[m2]-av2,2.0);

          Again, s1, s2 should be declared double. Those declarations will fix the (otherwise wrong) above expression . BTW: Are you aware that all that static_casts you're using are useless (and contributes to overall code entropy)? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          G 1 Reply Last reply
          0
          • CPalliniC CPallini

            gentleguy wrote:

            av1=a4/_iBoundwidth; av2=a5/_iBoundwidth;

            av1, av2 should be declared double (or float). Then change the above expression to:

            av1 = (double)a4 / _iBoundwidth;
            av2 = (double)a5 / _iBoundwidth;

            gentleguy wrote:

            s1=s1+pow(nColumnCounts4[m2]-av1,2.0); s2=s2+pow(nColumnCounts5[m2]-av2,2.0);

            Again, s1, s2 should be declared double. Those declarations will fix the (otherwise wrong) above expression . BTW: Are you aware that all that static_casts you're using are useless (and contributes to overall code entropy)? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            G Offline
            G Offline
            gentleguy
            wrote on last edited by
            #5

            thanks however i couldn't get nColumnCOunts4,5 arrays value. what is problem. i corrected as per your remind.thanks a lot.

            int *nColumnCounts = new int[_iBoundwidth]; //whole image
            int *nColumnCounts1 = new int[_iBoundwidth]; //1st part
            int *nColumnCounts2 = new int[_iBoundwidth]; //2nd part
            int *nColumnCounts3 = new int[_iBoundwidth]; //3rd part
            int *nColumnCounts4 = new int[_iBoundwidth];
            int *nColumnCounts5 = new int[_iBoundwidth];

            for (int i=0;i&lt;\_iBoundwidth;i++)
            {
            	nColumnCounts1\[i\]=0;
            	nColumnCounts2\[i\]=0;
            	nColumnCounts3\[i\]=0;
                nColumnCounts4\[i\]=0;
            	nColumnCounts5\[i\]=0;
            	nColumnCounts\[i\]=0;
            }
            

            int a = _iBoundheight%3; // remainder for(iY=0;iY<(a+(static_cast<int>(_iBoundheight/3)));iY++) { for (iX=_iBoundx;iX<_iBoundwidth;iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts1[iX]++; } } } for(iY=(a+(static_cast<int>(_iBoundheight/3)));iY<(a+2*(static_cast<int>(_iBoundheight/3)));iY++) { for(iX=_iBoundx; iX<_iBoundwidth; iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts2[iX]++; } } } for(iY=(a+2*(static_cast<int>(_iBoundheight/3)));iY<_iBoundheight;iY++) { for(iX=_iBoundx; iX<_iBoundwidth; iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts3[iX]++; } } } // Average int a1,a2,a4,a5,s1,s2,s3,r1,r2,r3,av1,av2; a4=a5=0; s1=s2=0; r1=r2=0; av1=av2=0; // Standard deviation for (int m=0;m<_iBoundwidth;m++) { nColumnCounts4[m]=abs(nColumnCounts1[m]-nColumnCounts2[m]); nColumnCounts5[m]=abs(nColumnCounts2[m]-nColumnCounts3[m]); a4=a4+nColumnCounts4[m]; a5=a5+nColumnCounts5[m]; } av1=a4/_iBoundwidth; av2=a5/_iBoundwidth; for (int m2=0;m2<_iBoundwidth;m2++) { s1=s1+pow(nColumnCounts4[m2]-av1,2.0); s2=s2+pow(nColumnCounts5[m2]-av2,2.0); } _fFeature[0] = sqrt(s1/_iBoundwidth); _fFeature[1] = sqrt(s2/_iBoundwidth); delete[] ImgArray; delete[] nColumnCounts1; delete[] nColumnCounts2; delete[] nColumnCounts3; delete[] nColumnCounts; delete[] nColumnCounts4; delete[] nColumnCounts5; return true;}

            gentleguy

            CPalliniC 1 Reply Last reply
            0
            • G gentleguy

              thanks however i couldn't get nColumnCOunts4,5 arrays value. what is problem. i corrected as per your remind.thanks a lot.

              int *nColumnCounts = new int[_iBoundwidth]; //whole image
              int *nColumnCounts1 = new int[_iBoundwidth]; //1st part
              int *nColumnCounts2 = new int[_iBoundwidth]; //2nd part
              int *nColumnCounts3 = new int[_iBoundwidth]; //3rd part
              int *nColumnCounts4 = new int[_iBoundwidth];
              int *nColumnCounts5 = new int[_iBoundwidth];

              for (int i=0;i&lt;\_iBoundwidth;i++)
              {
              	nColumnCounts1\[i\]=0;
              	nColumnCounts2\[i\]=0;
              	nColumnCounts3\[i\]=0;
                  nColumnCounts4\[i\]=0;
              	nColumnCounts5\[i\]=0;
              	nColumnCounts\[i\]=0;
              }
              

              int a = _iBoundheight%3; // remainder for(iY=0;iY<(a+(static_cast<int>(_iBoundheight/3)));iY++) { for (iX=_iBoundx;iX<_iBoundwidth;iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts1[iX]++; } } } for(iY=(a+(static_cast<int>(_iBoundheight/3)));iY<(a+2*(static_cast<int>(_iBoundheight/3)));iY++) { for(iX=_iBoundx; iX<_iBoundwidth; iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts2[iX]++; } } } for(iY=(a+2*(static_cast<int>(_iBoundheight/3)));iY<_iBoundheight;iY++) { for(iX=_iBoundx; iX<_iBoundwidth; iX++) { if (ImgArray[iX+iY*_iBoundwidth] == 255) { nColumnCounts3[iX]++; } } } // Average int a1,a2,a4,a5,s1,s2,s3,r1,r2,r3,av1,av2; a4=a5=0; s1=s2=0; r1=r2=0; av1=av2=0; // Standard deviation for (int m=0;m<_iBoundwidth;m++) { nColumnCounts4[m]=abs(nColumnCounts1[m]-nColumnCounts2[m]); nColumnCounts5[m]=abs(nColumnCounts2[m]-nColumnCounts3[m]); a4=a4+nColumnCounts4[m]; a5=a5+nColumnCounts5[m]; } av1=a4/_iBoundwidth; av2=a5/_iBoundwidth; for (int m2=0;m2<_iBoundwidth;m2++) { s1=s1+pow(nColumnCounts4[m2]-av1,2.0); s2=s2+pow(nColumnCounts5[m2]-av2,2.0); } _fFeature[0] = sqrt(s1/_iBoundwidth); _fFeature[1] = sqrt(s2/_iBoundwidth); delete[] ImgArray; delete[] nColumnCounts1; delete[] nColumnCounts2; delete[] nColumnCounts3; delete[] nColumnCounts; delete[] nColumnCounts4; delete[] nColumnCounts5; return true;}

              gentleguy

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Please re-format your code. [added] actually you did follow NONE of my advices (as can be seen in posted code). [/added] :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              modified on Thursday, July 17, 2008 3:09 AM

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups