MATLAB Answers

How to plot a triangular shape function on a triangular domain?

61 views (last 30 days)
Hello, I want to plot the following shape function: N(s,t)=t*(2*t-1) It has to look like the following diagramm:
but I get this one:
Here is my code:
I know that the problem is with the rectangular domain, that meshgrid generates. But I don't know how to define a triangular domain. Has anybody an idea?


Sign in to comment.

Accepted Answer

Mike Garrity
Mike Garrity on 25 Apr 2016
I described one approach in this thread.


Soroush Asarzadeh
Soroush Asarzadeh on 26 Apr 2016
Hi Mike, Thank you for your quick answer. Unfortunately I can't apply it to my case. In your approach you have used: out = w<0; which is not going to work in my case. Can you please make it more clear by helping me to define the exclusion area?
When I even manage to do that, I'll have NaN elements in my N3-matrix, which causes the following error:
Subscript indices must either be real positive integers or logicals.
any idea about this?
Mike Garrity
Mike Garrity on 26 Apr 2016
I think that passing a function handle into surf is making things more complicated than you really need.
I don't know what N3 is, but using the N from the top, I get this:
[s,t] = meshgrid(0:0.025:1);
z = t.*(2*t-1);
z(s+t > 1) = nan;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by