Does MATLAB Coder support 'persistent' variables?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Walter Roberson
2015 年 7 月 28 日
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
2015 年 7 月 28 日
編集済み: Guillaume
2015 年 7 月 28 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!