The code provided is not recognizing the decimal_Fm as a variable, making this function uselless when placed into another m file. Any suggestions?
古いコメントを表示
function percent_Fm = sarcomere_force(percent_L)
decimal_L = percent_L/100;
L = decimal_L*2.7; % micrometers
if 1.35<=L && L<=1.91
decimal_Fm = 1.41*L-1.91
elseif 1.91<L && L<=2.37
decimal_Fm = 0.40*L+0.04
elseif 2.37<L && L<=2.71
decimal_Fm = 0.04*L+0.89
elseif 2.37<L && L<=4.53
decimal_Fm=-0.50*L+2.35
end
percent_Fm = decimal_Fm*100;
As a note, I know there is no percent_L given. That is something solved for in the other m file.
回答 (1 件)
Mathieu NOE
2022 年 3 月 3 日
hello
I fixed your code :
- the function was missing and else statement in case the L values are not in the numerical range already coded. For this case you have to decide what value (or leave empty) you want.
- the function(s) are always located at the lower end of the script, you do the function call above the function script
clc
clearvars
%% main code
percent_L = 100;
percent_Fm = sarcomere_force(percent_L);
%% functions
function percent_Fm = sarcomere_force(percent_L)
decimal_L = percent_L/100;
L = decimal_L*2.7; % micrometers
if 1.35<=L && L<=1.91
decimal_Fm = 1.41*L-1.91;
elseif 1.91<L && L<=2.37
decimal_Fm = 0.40*L+0.04;
elseif 2.37<L && L<=2.71
decimal_Fm = 0.04*L+0.89;
elseif 2.37<L && L<=4.53
decimal_Fm=-0.50*L+2.35;
else % here
decimal_Fm=[]; % or ??? to be defined
end
percent_Fm = decimal_Fm*100;
end
3 件のコメント
Kevinjw16
2022 年 3 月 3 日
Kevinjw16
2022 年 3 月 3 日
Mathieu NOE
2022 年 3 月 3 日
hello
for your function you need and additionnal "end" - that was missing in your code
- there must be one "end" for the if loop
- a second end to "close" the function
see my code example and double check yours
function percent_Fm = sarcomere_force(percent_L)
decimal_L = percent_L/100;
L = decimal_L*2.7; % micrometers
if 1.35<=L && L<=1.91
decimal_Fm = 1.41*L-1.91;
elseif 1.91<L && L<=2.37
decimal_Fm = 0.40*L+0.04;
elseif 2.37<L && L<=2.71
decimal_Fm = 0.04*L+0.89;
elseif 2.37<L && L<=4.53
decimal_Fm=-0.50*L+2.35;
else % here
decimal_Fm=[]; % or ??? to be defined
end
percent_Fm = decimal_Fm*100;
end
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!