필터 지우기
필터 지우기

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

조회 수: 12 (최근 30일)
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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by