Hello Yago,
To map each power entry to its corresponding efficiency based on torque and speed values, you can use 'find' function as shown below:
% Example efficiency matrix (21x8)
efficiencyMatrix = rand(21, 8);
torqueBins = [40, 50, 60, 70, 80, 90, 100, 110, 120]; % torque bin edges
speedBins = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200]; % Example speed bin edges
% Example torque and speed arrays
torqueArray = [45, 55, 65, 75, 85, 95, 105, 115];
speedArray = [150, 250, 350, 450, 550, 650, 750, 850];
efficiencyArray = zeros(size(torqueArray));
% Function to find bin index
findBinIndex = @(value, bins) find(value >= bins(1:end-1) & value < bins(2:end), 1);
% Map each torque and speed value to the corresponding efficiency
for i = 1:length(torqueArray)
torqueIdx = findBinIndex(torqueArray(i), torqueBins);
speedIdx = findBinIndex(speedArray(i), speedBins);
if ~isempty(torqueIdx) && ~isempty(speedIdx)
efficiencyArray(i) = efficiencyMatrix(speedIdx, torqueIdx);
else
efficiencyArray(i) = NaN;
end
end
disp('Torque values:');
disp(torqueArray);
disp('Speed values:');
disp(speedArray);
disp('Mapped Efficiency values:');
disp(efficiencyArray);
Kindly refer to the documentation by executing the following command in MATLAB Command Window to know more about 'find' function :
doc find