Borrar filtros
Borrar filtros

MATLAB coder error:Unable to determine that every element of cell is assigned before this line

8 visualizaciones (últimos 30 días)
WHEN USING MATLAB CODER TO GENERATE C CODE,
I faced up with the error :"Unable to determine that every element of 'region{:}' is assigned before this line. "
I checked the guidance and set the code into form the same as which in the guidance:
region = cell(rlen,1);
for rn = 1:rlen
region{rn}=[0,0];
end
But the error still in. Anyone can help?
Thanks a lot.
Followed as part of my code:
region = cell(rlen,1);
for rn = 1:rlen
region{rn}=[0,0];
end
%% region init
regionr = int16(zeros(length(region),1));
for ii = 1:length(region)
regionr(ii) = int16(sqrt(double(region{ii}(1)^2 +double(region{ii}(2)^2))));
%% error occured here:
%%Unable to determine that every element of 'region{:}' is assigned before this line.
end
  3 comentarios
wu you
wu you el 3 de Dic. de 2021
I met with the error while using the tool: matlab coder. It works normally in matlab environment.
It's my fault not to clarify it at first. The question has been re-edited.
Jan
Jan el 3 de Dic. de 2021
The code can be simplified:
% ------------------------------------
region = cell(rlen,1);
for rn = 1:rlen
region{rn} = [0,0];
end
% Shorter and faster:
region = cell(rlen, 1);
region(:) = {[0, 0]};
% ------------------------------------
regionr = int16(zeros(length(region),1));
% Faster:
regionr = zeros(rlen, 1, 'int16');
% ------------------------------------
for ii = 1:length(region)
regionr(ii) = int16(sqrt(double(region{ii}(1)^2 +double(region{ii}(2)^2))));
end
% Easier: region{ii} is a double already. You cast region{ii}(2)^2 to a
% double, add it to region{ii}(1)^2 and cast the result to a double again.
% This is confusing only. Leaner:
for ii = 1:rlen
regionr(ii) = int16(sqrt(region{ii}(1)^2 + region{ii}(2)^2));
end
But I do not see an error also.

Iniciar sesión para comentar.

Respuesta aceptada

wu you
wu you el 3 de Dic. de 2021
Editada: Walter Roberson el 3 de Dic. de 2021
I tried the 3rd method provided in the guidance, it works. Just like code below:
region1 = cell(rlen,1);
region = coder.nullcopy(region1);
for rn = 1:rlen
region{rn}=f{rn+left};
end
But i still wonder why the 1st method i used does not work.

Más respuestas (0)

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by