필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help with array question.

조회 수: 1 (최근 30일)
Matthew Gulledge
Matthew Gulledge 2014년 2월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
I have this quiestion on a homework of mine:
Write a function called triAreaN that computes the area of N triangles. The input to the function is a 2 x N array where each column of the array contains the base and height of a single triangle. The function returns a 1 x N array where the ith column is the area of the ith triangle. You should test whether the base and height are positive. If either one is negative, set the area of that triangle to zero.
this is what i have currently:
%Calculates area of multiple triangles-N.
%Alkaline Matt Gulledge
function area = triAreaN(A,B)
N = input('Input value for N');
i = input('Input value for i');
A=rand(2,N)
A(:,i)
area = i
How do i use the two data points at column i and apply base*height/2 to those to points?

답변 (1개)

Anuj
Anuj 2014년 2월 13일
function area = triAreaN(A,B)
N = input('Input value for N');
i = input('Input value for i');
A=rand(2,N)
A(find(A<0))=0;
Area=A(1,:).*A(2,:)*1/2
So, this Area is your 1xN array. you can access area of ith triangle by
Area(i)
Regards

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by