HELP!!! mapping with matrices

조회 수: 2 (최근 30일)
Yago
Yago 2012년 1월 28일
답변: nick 2025년 4월 16일
I have a peculiar problem and I've hit a massive wall. I am modeling driveline efficiencies and have a matrix with different engine efficiencies depending on torque and engine speed. I didn't know how to do this so I manually created a matrix with efficiency values for given ranges of torque and speed. For example, one row could be a specific range of speed (100-200 rpm) and each entry in that row is an efficiency corresponding to different ranges of torque (say 40-50 Nm, 50-60 Nm, etc,).
So I have a big bunch of efficiencies in a 21x8 matrix.
Now, I also have arrays for torque (vs. time) and speed (vs. time) and thus for POWER (vs. time). I now need to map each power entry to its corresponding efficiency, which depends on its torque and speed values at that time interval (to a specific entry in the efficiency map matrix). I don't know how to tell MATLAB to do so... Unless I create a massive LOOP with thousands os IFs...)
Please any help appreciated!

답변 (1개)

nick
nick 2025년 4월 16일
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:');
Torque values:
disp(torqueArray);
45 55 65 75 85 95 105 115
disp('Speed values:');
Speed values:
disp(speedArray);
150 250 350 450 550 650 750 850
disp('Mapped Efficiency values:');
Mapped Efficiency values:
disp(efficiencyArray);
0.9749 0.6528 0.4996 0.4454 0.4635 0.0423 0.0676 0.1024
Kindly refer to the documentation by executing the following command in MATLAB Command Window to know more about 'find' function :
doc find

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by