Reputation: 23
I working on a homework assignment and trying to solve the following problem:
Here is the code I have so far:
function [ ] = Activity45( Time )
%Homework 4
%Activity 4.5
t=Time;
A=[0:0.1:t];
B=3*exp(-(A/3)).*sin(pi.*A);
C=(B>0);
plot(A,B(C))
end
So I am trying to use a mask to extract the data from Matrix B in Matrix C. But I do not know how to match the data up between A and C, to then use plot().
Any help?
Upvotes: 0
Views: 55
Reputation: 36710
With plot(A(C), B(C))
you don't get the intended curve because you don't have values equal to zero. Instead the last two points to the left and right are connected with a line above 0. The right way would be to set the value on the Y-Axis to zero.
B(~C)=0;
plot(A,B);
For future formulas, it might be a good idea to use variable names matching the variable names in your formulas.
Upvotes: 1