I have this function where standard_time and E are part of a table. I want to create a new column from this function as such.
T.solar_time = calc_solar_time(T.standard_time, L_st, L_loc, T.E);
function solar_time = calc_solar_time(standard_time, L_st, L_loc, E)
if standard_time == 0
solar_time = 24 * 60 + 4 * (L_st - L_loc) + E;
else
solar_time = 4 * (L_st - L_loc) + E;
end
end
The function acts as if its written like below. As in it just uses the solar_time definition which it reaches the first time.
function solar_time = calc_solar_time(standard_time, L_st, L_loc, E)
solar_time = 4 * (L_st - L_loc) + E;
end
L_st and L_loc are constants.
The table is like this.. https://www.hizliresim.com/6amb7qx

 채택된 답변

Walter Roberson
Walter Roberson 2022년 5월 15일

1 개 추천

T.solar_time = calc_solar_time(T.standard_time, L_st, L_loc, T.E);
That is passing in all entries from the table at the same time.
You have three major choices:
  • rewrite your function to use logical indexing
  • rewrite your function to loop
  • change the way you call your function to call it using arrayfun()

댓글 수: 3

Thnak you, I thınk I'll just use loops
Logical indexing is what I would recommend.
Thank you, I just learned about them. Makes the code look really neat.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Trigonometry에 대해 자세히 알아보기

제품

릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by