433 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)

Walter Roberson
on 10 Aug 2020

Ramakant Gupta
on 15 May 2020

Edited: Walter Roberson
on 2 Jun 2020

function area = tri_area(b,h)

area = 0.5*b*h;

end

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

Start Hunting!
## 10 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

## 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_966391

⋮## 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_966391

## 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_966445

⋮## 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_966445

## 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_987749

⋮## 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_987749

Sign in to comment.