How do I get every combo of a two vectors to put into an equation?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to multiple every combo of two unequal vectors. The first is Roll = 0:5:180 , (0, 5, 10, 15...180); the second is Pitch = 0:5:90 (0, 5, 10...90)
I need to then put every combo of those in this equation:
for (every combo of Roll and Pitch values) <<what type of for loop would I put here ?
if Roll > 40 && Pitch > 40
((180/Roll) + (90/Pitch))/2
if Roll > 40
180/Roll
if Pitch > 40
90/Roll
else
0
end
end
I am hoping to graph all the combos after they go through this equation. e.g the combos could be roll = 5 , pitch =10; roll =15, pitch = 80; roll = 60, pitch = 80 and so on...
0 个评论
回答(1 个)
Guillaume
2019-7-23
It's really not clear what your if statements are meant to do since you wrote some calculations that are not assigned to anything. In any case, the efficient way to do whatever you want to do is not to use if or loops:
Roll = 0:5:180;
Pitch = 0:5:90;
[Roll, Pitch] = ndgrid(Roll, Pitch); %cartesian product of the 2 sets
%taking a guess at what you want to do. Your conditions don't make sense
Result = zeros(size(Roll));
Result = 180 ./ Roll + 90 ./ Pitch / 2; %generic case
Result(Roll < 40) = 180 ./ Roll(Roll < 40); %other condition
Result(Pitch < 40) = 90 ./ Roll(Pitch < 40); %other condition
surf(Roll, Pitch, Result);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!