필터 지우기
필터 지우기

How can i apply vector of time in this function?

조회 수: 5 (최근 30일)
Samantha Pham
Samantha Pham 2020년 9월 22일
이동: Steve Miller 2022년 12월 20일
I have these codes below that calculate I and Is.
When i use Brightness(40,10,3), it gave me the desired result. This is the single time value
i want to use Brightness with vector like this: Brightness(40,0:0.01:10,3), how do i change the codes below to use this
Note: this is errors i received when i tried to use for vector time value --> Variable y has an incorrect value. Your function was unable to calculate the correct brightness for multiple times (0:0.01:10). Utilize Eq. 1 to calculate the brightness without factoring in the power surge. Utilize Eq. 2 to calculate the ADDITIONAL brightness caused by the power surge. However, some time values in the vector will be less than the surge time; therefore, they will not have the additional brightness added by the surge. Use logical statements to add the additional surge brightness only to values at times greater than the time of surge.
function I = Brightness(Power, Time, Surge)
I = 15*Power*( 1 - 1.4*exp(-Time).*sin( 1.43*Time + pi/4 )); %equation 1
Is = 10*Power*exp(-1)*sin(1.43/2); %equation 2
for i = 1:length(Time)
if Time(i) > Surge
I(i) = I(i) + Is;
end
end
  댓글 수: 4
Turlough Hughes
Turlough Hughes 2020년 9월 22일
Happy to help :)
Adam Danz
Adam Danz 2020년 9월 22일
편집: Adam Danz 2020년 9월 22일
No need for the for-loop. Use indexing.
I = 15*Power*( 1 - 1.4*exp(-Time).*sin( 1.43*Time + pi/4 )); %equation 1
Is = 10*Power*exp(-1)*sin(1.43/2); %equation 2
idx = Time < Surge;
I(idx) = I(idx) + Is;

댓글을 달려면 로그인하십시오.

답변 (1개)

Turlough Hughes
Turlough Hughes 2020년 9월 22일
이동: Steve Miller 2022년 12월 20일
It looks like your code is doing what it is supposed to do based on the info provided, maybe try changing your > sign to >=

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by