Clear Filters
Clear Filters

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

12 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 7 Dec 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()

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!