HELP!!! mapping with matrices
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Antworten (1)
nick
am 16 Apr. 2025
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
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!