1,577 views (last 30 days)

hello this is my function code and command window code and there is a message of invalid expression at line 2 and i dont know what is the wrong can anyone help me

function [area] = tri_area([b,h]);

tri_area([b,h])=(0.5)*(b)*(h)

area=tri_area([b,h])

end

%command window

area = tri_area[3,2])

Torsten
on 9 Apr 2020

Edited: darova
on 9 Apr 2020

function area = tri_area(b,h)

area = 0.5*b*h;

end

From the command window

A = tri_area(3,2)

Alric Duarte
on 21 Jun 2020 at 13:22

someone please tell the solution for random inputs. i got the same error as above

Walter Roberson
on 21 Jun 2020 at 21:28

Ramakant Gupta
on 15 May 2020

Edited: Walter Roberson
on 2 Jun 2020 at 23:09

function area = tri_area(b,h)

area = 0.5*b*h;

end

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_846810

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_846810

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_847571

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_847571

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_848805

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_848805

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_849719

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_849719

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_867373

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_867373

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_867603

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_867603

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_886589

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/516676-write-a-function-called-tri_area-returns-the-area-of-a-triangle-with-base-b-and-height-h#comment_886589

Sign in to comment.