CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Dynamic Matrix

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Engeletrica



Joined: 11 Jan 2012
Posts: 1

View user's profile Send private message AIM Address

Dynamic Matrix
PostPosted: Wed Jan 11, 2012 5:47 am     Reply with quote

Hello Everyone!!

I need construct a matrix where the values are dynamic.
For example:
Code:

{a b c
  e f g}

Where, a,b,c,d,e ,f e g are variables and can be modified for users.
Somebody can help me?
I put piece of my code in order easily help.
Code:

int a,b,c,d,e,f;

a=50;
b=20;
c=40;
d=30;
e=90;
f=70;

av[0]=a;
av[1]=b;
av[2]=c;
av[3]=d;
av[4]=e;
av[5]=f;

while(true)
{
long const rotacao [2][6]={{ 0  ,  40 ,  80 ,  120 , 160 ,  200 }
                                             {av[0];av[1];av[2];av[3];av[4];av[5]}};

signed long rot_min=0;
signed long rot_max=0;
signed long av_min=0;
signed long av_max=0;
signed long z=0;
signed long z1=0;
signed long z2=0;
signed long c1=0;
signed long c2=0;
       
set_tris_a(0b00001000);
set_adc_channel(3);
xa=read_adc();

for (j=0;j<=6;j++)
   {       
      rot_min=rotacao[j];
      //rot_max=rotacao[i+1];
      if(xa>=rot_min)
         {
         rot_max=rotacao [j+1];
         if(xa<=rot_max)
            {
            av_min=av [j];
            av_max =av [j+1];
            c1=av_max-av_min;
            c2=rot_max-rot_min;
            z=c1/c2;
            //z=(long)((av_max-av_min)/(rot_max-rot_min));
            z1=av_min-z*rot_min;
            z2=(long int)((z*xa)+z1);
            }
         
         }
   }

Sorry, my mistakes in english.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jan 11, 2012 3:01 pm     Reply with quote

perhaps you would like to show a more complete program -
that actually COMPILES??
Brandon03



Joined: 11 Jan 2012
Posts: 3

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 12:14 am     Reply with quote

There are two common approaches. For N rows with M columns each:

One is to simulate the matrix with a one-dimensional array. You
allocate space for N*M objects, as with
T *ptr = malloc(N * M * sizeof *ptr);
and you reference the (i,j)th element by calculating the appropriate
subscript yourself, as in
ptr[i*M+j] = 0;

The other is to build an array of pointers, each pointing to one
row of the matrix, as in
T **ptr = malloc(N * sizeof *ptr);
for (k = 0; k < N; k++)
ptr[k] = malloc(M * sizeof *ptr[k]);
and you reference the (i,j)th element using the natural syntax, as in
ptr[i][j] = 0;

In either case, you pass the array to a function by using the ptr
variable. Note, since N and M are not known until run time:

Using the first approach always requires M to be available to the
function.

In either approach, the function will need both N and M if it is
concerned in any way with the top or right boundary elements of the
matrix.

The second approach is more flexible in that it can handle jagged
arrays where M is not constant for each row.


<<Remove the del for email>>
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group