Clear Filters
Clear Filters

Hi, guys, I am trying to create a MATLAB Subrountine, but I faced some problems. My code is not working, and I don't know what is wrong with it.

1 view (last 30 days)
Error:
("??? Error: File: EXPERI.m Line: 4 Column: 1
Function definitions are not permitted in this context.")
clc
clear
function [x] = getcond(t1, t2 , material);
% GETCOND calculates the conductance given the two temperatures and
% material involved.
%INPUTS:
% t1 - high temperature
% t2 - low temperature
% material - (string) material being used.
%OUTPUTS:
% returns the conductance
%EXAMPLE:
% result = GETCOND(300, 77, 'aluminum')
t1 = input('Enter Low Temperature');
t2 = input('Enter High Temperature');
material = input('Enter Constant, k');
%Classify according to "material"
if material = printf('aluminum_high');
k = [0.10974, 0.019819, -7.7701e-5, 1.04e-7]*100;
elseif material = printf('steel_high');
k = [-0.00551407, 0.001541448, -5.59e-6, 8e-9]*100;
else material = printf('Error: Do not recognize material');
k = [0];
end
cond = k[0]*(t1-t2)+k[1]*(t1^2-t2^2)/2.+k[2]*(t1^3-t2^3)/3.+k[3]*(t1^4-t2^4)/4;
x = cond / (t1 - t2);
end
T_1=100;
T_2=200;
K_1=getcond(T_1, T_2, 'aluminum_high')

Answers (2)

ES
ES on 4 Sep 2013
Did you write your function in command window? Unlike python, MATLAB does not let you write a function in its command window. So create an m file with your function and call it from command line.
Thanks!

Laurent
Laurent on 4 Sep 2013
Try to remove the first three lines ('clc', 'clear' and the empty line), then rename your file, or function, so that the filename and function name are the same. You also don't need the semi-colon behind the 'function' line.
After that I don't see why this should not work.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!