Does MATLAB Coder support 'persistent' variables?
1 view (last 30 days)
Show older comments
Hello again.
I have another problem with MATLAB coder. Here is the code.
Function C_td = make_CA_matrix(C_array, A_array, k, N_h)
N_h : horizon length
global N_horizon
persistent count C_tilde;
if isempty(count)
count = 0;
else
count = count + 1;
end
if isempty(C_tilde)
C_tilde = zeros(4*N_horizon,3);
end
index_Cmat = k - N_h;
C_tilde(1:4,:) = C_array(:,:,index_Cmat);
N_state = size(A_array(:,:,1),2);
A = eye(N_state);
for i = 1 : N_h-1
index_Amat = k - N_h + i - 1;
A = A_array(:,:,index_Amat)*A;
index_Cmat = k - N_h + i;
C_tilde(i * 4 + 1: i * 4 + 4,:) = C_array(:,:,index_Cmat)*A;
end
C_td = C_tilde(1:N_h * 4, :);
end
When I tried to convert this MATLAB code to C code with MATLAB coder, This Error Message I met.
This assignment writes a 'double' value into a 'int32' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches. (C_tilde)
Do you have any Idea to Fix this problem?
0 Comments
Answers (2)
Walter Roberson
on 28 Jul 2015
Yes, it does support persistent. See http://www.mathworks.com/help/coder/ug/defining-and-initializing-persistent-variables.html
Which statement is being identified as having the error? If it is the last statement then try initializing C_td near the beginning.
Guillaume
on 28 Jul 2015
Edited: Guillaume
on 28 Jul 2015
I suspect the error is on this line
C_tilde(1:4,:) = C_array(:,:,index_Cmat);
and that C_array is of class int32. Declare C_tilde of the same type:
C_tilde = zeros(4*N_horizon, 3, 'int32');
%or better, if supported by coder:
C_tilde = zeros(4*N_horizon, 3, 'like', C_array);
This has nothing to do with persistent.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!