How do I get every combo of a two vectors to put into an equation?

조회 수: 1 (최근 30일)
Katharine Woodruff
Katharine Woodruff 2019년 7월 23일
댓글: Katharine Woodruff 2019년 7월 25일
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...

답변 (1개)

Guillaume
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);
  댓글 수: 1
Katharine Woodruff
Katharine Woodruff 2019년 7월 25일
Thank you!
I figured out how to get that matrix. However, when I plot the matrix of the 3 columns, it does not graph as expected.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by