Indentify spcific point of matrixs

1 回表示 (過去 30 日間)
Felix Hao
Felix Hao 2020 年 4 月 21 日
コメント済み: Felix Hao 2020 年 4 月 21 日
currently I have two matrix which is drag and thrust as you see below, and the number of two martix is going to be very close at some point, and I need to find out what the spcific number of drag and thrust when they are really close to each other, I have try to write the flowing function, but it only return the orginal matrix of thrust
function [maxSpeed,thrustDragVal] = maxSpeedThrustCalc(V, thrust, drag)
for difference = thrust - drag
if abs(difference) <= 0.01
maxSpeed = V;
thrustDragVal = thrust;
end
end

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 21 日
Hi Felix,
I see that the for loop condition is not correct. You can try the following
function [maxSpeed,thrustDragVal] = maxSpeedThrustCalc(V, thrust, drag)
for i = 1:length(thrust)
difference = thrust(i) - drag(i);
if abs(difference) <= 0.01
maxSpeed = V;
thrustDragVal = thrust(i);
end
end
end
% You mentioned that drag and thrust need to be known, but i am not sure why the output is set to maxSpeed
% You indicate the minimum difference, but why is the threshold placed as 0.01
% If both the above is same as what is said, you need to use the following code
difference = thrust - drag;
[m,i] = min(abs(difference)); % m is the minimum value and i is the index where minimum occurs
thrustVal = thrust(i);
dragVal = drag(i);
Hope this helps.
Regards,
Sriram
  4 件のコメント
Felix Hao
Felix Hao 2020 年 4 月 21 日
Thank you sir!
Felix Hao
Felix Hao 2020 年 4 月 21 日
Sorry Sir, I hate to bother you again, but do you know how can I make it only return the intersection on the right, now it return the intersection point on the left.
Really Appreciate it !
The functioin I used:
function [maxSpeed,thrustDragVal] = maxSpeedThrustCalc(V, thrust, drag)
for difference = drag - thrust
[m,i] = min(abs(difference));
if (abs(difference) == m)
maxSpeed = V(i);
thrustDragVal = thrust(i);
end
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by