The code provided is not recognizing the decimal_Fm as a variable, making this function uselless when placed into another m file. Any suggestions?
Show older comments
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.
Answers (1)
Mathieu NOE
on 3 Mar 2022
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 Comments
Kevinjw16
on 3 Mar 2022
Kevinjw16
on 3 Mar 2022
Mathieu NOE
on 3 Mar 2022
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
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!