フィルターのクリア

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

12 ビュー (過去 30 日間)
Rishika
Rishika 2023 年 11 月 30 日
回答済み: Walter Roberson 2023 年 12 月 7 日
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

採用された回答

Walter Roberson
Walter Roberson 2023 年 12 月 7 日
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()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by