 # can you help me i want to convert this code from matlab to arduino.c

x=[2 3 1; 1 4 2;3 3 1];% Image h=[1 1 1; 2 0 1;0 1 2];% Filter m=size(x);% Save the size of image matrix (3x3) n=size(h);% save size of filter matrix (3x3) M1=m(1)%save value of the row of the image matrix M2=n(1)%save value of the row of the filter matrix N1=m(2)%save value of the column of the image matrix N2=n(2)%save value of the column of the filter matrix X=[x,zeros(M1,N1)];% expantion the image matrix (3 x 6 ) X=[X;zeros(M1,N1*2)];% expantion the image matrix (6 x 6 ) H=[h,zeros(M2,N2)];% expantion the image matrix (3 x 6 ) H=[H;zeros(M2,N2*2)];% expantion the image matrix (6 x 6 )

for i=1:M1+M2-1 for k=1:N1+N2-1 y(i,k)=0; for j=1:M1 for s=1:N1 if(i-j+1>0&&k-s+1>0) y(i,k)=y(i,k)+X(j,s)*H(i-j+1,k-s+1); end end end end end y

Maybe this gets you further in translating from the language in your example code (Matlab?) into C/C++ which is used by Arduino:

``````// comment example and array definition example
int x[ 3 ] [ 3 ] = { 2, 3, 1 } , { 1, 4, 2} , { 3, 3, 1 } ;

// for loop with loop counter ( i ) incremented by 1 each iteration
for ( int i = 1 ; M1 + M2 -1 ; i++ ) {
// do stuff in loop
}

// if statement and array addressing
if(i-j+1>0 && k-s+1>0) {
y[i][k] =y[i][k] +X[j][s] * H[i-j+1][k-s+1] ;
}
``````

thanks but this code no help me it have many problem

omarmah: thanks but this code no help me it have many problem

I am not surprised that this did not work directly. It was intended a series of examples of equivalents of the major constructs you appear to be using. You haven't said what you are going to do with the output. If you want to print it to the serial console, you'll also need Serial.print().

If you want to pay someone to code it for you, get a moderator to move it into the section "Gigs and Collaborations" section of the forum by using the "report to moderator" function.

Another thing to remember as you convert your code from Matlab to C / C++ is that in the former arrays start at Index 1 while in the latter they start with Index 0.