Effacer les filtres
Effacer les filtres

Caused by: MATLAB expression '<output of containers.Map>' is not numeric.

12 vues (au cours des 30 derniers jours)
I created a code in matlab SIMULINK using matlab function. But it keeps saying
Caused by: MATLAB expression '<output of containers.Map>' is not numeric.
Pasting the code for reference, thanks.
function activePlants = ctp(costs, loads, capacities)
coder.extrinsic('containers.Map')
costToPlant=zeros();
costToPlant = containers.Map('KeyType', 'double', 'ValueType', 'double');
for plant = 1:length(costs)
costToPlant(costs(plant)) = plant;
end
sortedCosts = sort(costs);
for loadIndex = 1:length(loads)
netCapacity = 0;
activePlants =zeros();
costIndex = 1;
while costIndex <= length(sortedCosts)
currentPlant = costToPlant(sortedCosts(costIndex));
if netCapacity >= loads(loadIndex)
break;
else
netCapacity = netCapacity + capacities(currentPlant);
activePlants = [activePlants, costs(currentPlant)];
end
costIndex = costIndex + 1;
end
if netCapacity >= loads(loadIndex)
fprintf('Active Plants for load %int8: %s\n', loads(loadIndex), (activePlants));
else
fprintf('Insufficient capacity for load %int8\n', loads(loadIndex));
end
disp(loads(loadIndex),(activePlants))
end
% Example arrays
%capacities = [3, 4, 5];
%loads = [7, 5, 8];
%activePlants = myFunction(costs, loads, capacities);
end

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Déc 2023
costToPlant=zeros();
costToPlant = containers.Map('KeyType', 'double', 'ValueType', 'double');
You initialize costToPlant as an empty double precision array.
Then you try to store containers.Map onto the same variable.
In Simulink, the datatype of a variable is determined by the first assignment to a variable. Once you have assigned a double precision datatype to costToPlant you cannot change the variable to containers.Map .
The fix is easy: just leave out the initialization to zeros()

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by