How do I solve this error: Variable-size Matrix type is not supported for HDL Code Generation?

I have developed an image encryption algorithm in MATLAB (not Simulink!) and want to implement it on an FPGA. Unfortunately, I do not know how to code in HDL. I would love to learn coding in HDL but I do not have the time at the moment. I'm trying to use the HDL Coder in MATLAB to convert my code into Verilog. I have successfully converted the code from floating-point to fixed-point. It works perfectly. But when I try to generate the HDL code I consistently get the following error:
<VARIABLE NAME>:Error: Variable-size matrix type is not supported for HDL Code Generation.
Any form of help and guidance in the right direction will be much appreciated.
Cheers.

Answers (1)

You need to supply a fixed (maximum) matrix size to work with, and arrange your code so that the real matrix size is known and used (e.g., don't loop to the size() of the matrix to handle variable sizing, because size() will be constant.)
Of course, the larger the matrix size you fix at, the more FPGA space it is going to occupy.

6 Comments

I understand what you mean but I'm just confused on how to implement it. Here's a snippet of my code. Could you maybe explain the same thing in syntax terms.
k=zeros(1,N);
x(1)=initial(1); y(1)=initial(2); z(1)=initial(3);
k(1)=mod((abs(x(1)-floor(x(1)))*10^14),256);
k(2)=mod((abs(y(1)-floor(y(1)))*10^14),256);
k(3)=mod((abs(z(1)-floor(z(1)))*10^14),256);
temp=3;
k=zeros(1,N*N);
% calculation of phase portraits /numerical solution/:
for i=2:N0
x(i)=(a*(y(i-1)-x(i-1)))*h - memo(x, c1, i);
k(temp+1)=mod((abs(x(i)-floor(x(i)))*10^14),256);
y(i)=(d*x(i)-x(i)*z(i-1)+c*y(i-1))*h - memo(y, c2, i);
k(temp+2)=mod((abs(y(i)-floor(y(i)))*10^14),256);
z(i)=(x(i)*y(i)-b*z(i-1))*h - memo(z, c3, i);
k(temp+3)=mod((abs(z(i)-floor(z(i)))*10^14),256);
temp=temp+3;
end
Why do you calculate k but then overwrite it all with zeros(1,N*N) ?
maxN = 50; %for example
assert( N0 <= MaxN );
k = zeros(1, MaxN * 3 + 3);
x(1)=initial(1); y(1)=initial(2); z(1)=initial(3);
k(1)=mod((abs(x(1)-floor(x(1)))*10^14),256);
k(2)=mod((abs(y(1)-floor(y(1)))*10^14),256);
k(3)=mod((abs(z(1)-floor(z(1)))*10^14),256);
temp = 3;
for i = 2 : N0
x(i)=(a*(y(i-1)-x(i-1)))*h - memo(x, c1, i);
k(temp+1)=mod((abs(x(i)-floor(x(i)))*10^14),256);
y(i)=(d*x(i)-x(i)*z(i-1)+c*y(i-1))*h - memo(y, c2, i);
k(temp+2)=mod((abs(y(i)-floor(y(i)))*10^14),256);
z(i)=(x(i)*y(i)-b*z(i-1))*h - memo(z, c3, i);
k(temp+3)=mod((abs(z(i)-floor(z(i)))*10^14),256);
temp=temp+3;
end
k = k(1:3*N0 + 3); %might not be needed or useable
Hey Walter, I did as you said but I continue to get the same error. Here's another code snippet. I really need some guidance with this. FYI n=300.
pointer=1;
mat=zeros(1000,1000);
for i=1:n
for j=1:n
mat(i,j)=vec(pointer);
pointer=pointer+1;
end
end
mat=mat(1:n,1:n);
X=zeros(1000,1000);
for j=1:n
for k=1:n
newj=mod(((j-1)+(k-1)),n)+1;
newk=mod(((j-1)+2*(k-1)),n)+1;
X(newj,newk)=mat(j,k);
end
end
X=X(1:n,1:n);
I do not have the appropriate to test with.
Not as an answer, but I wonder why you bother with two sets of "for" loops?
X = zeros(1000,1000);
for j = 1 : n
for k = 1 : n
newj = mod(((j-1)+(k-1)),n)+1;
newk=mod(((j-1)+2*(k-1)),n)+1;
X(newj,newk) = vec(pointer);
end
end
X = X(1:n, 1:n); %I am not sure this will be allowed.
Ya that last statement is not allowed. So how do I implement it?
Well the code may be a bit amateurish but the first loop converts a single-row vector in a square matrix and the second set of for-loops shuffles the position of the matrix entries. This code bit is for an image encryption algo. SO the matrix entries are pixel values and shuffling to done to change pixel position.

Sign in to comment.

Asked:

on 11 Apr 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!