Error Message: "Error: Function definitions are not permitted in this context." How do I fix this?

2 次查看(过去 30 天)
Hello, This is the function I have created function [R] = HydraulicRadius(W)
% ........
for D = 0.5:0.01:1.1
R=(W*D)/(W+2*D);
end
end
This is my input in the command window.
>> W=112.78;
>> function [R] = HydraulicRadius(W)
This is the output I get
??? function [R] = HydraulicRadius(W)
|
Error: Function definitions are not permitted in this context.
I'm not really sure why I am getting this error message. Any help would be greatly appreciated!

采纳的回答

Sarah Wait Zaranek
Sarah Wait Zaranek 2011-4-14
When you define a function in a file - you use the
function [R] = HydraulicRadius(W)
when you call it to use it, you do not use the word function as that is used for definition (aka your error message).
Call it like this:
R = HydraulicRadius(W)
(Note, you probably don't need the [], in the function definition)

更多回答(1 个)

Necs
Necs 2014-3-23
编辑:Necs 2014-3-23
Can some1 please help me. I have been trying to run this codes but getting a :: Function Definition not permitted.
HERE IS THE CODE.
>> %**************************************************************
% Filename : analysisFB.m
% Author : Necs
% Date : Aug 2014
% Purpose : Reconstruct the image using 2D forward discrete wavelet transform %**************************************************************
function wc = analysisFB(data,lpfilter,hpfilter)
[n_row,n_col] = size(data);
n = n_row;
le = length(lpfilter);
%###################### operation on the rows ##############################
pad_data = [data data(:,1:le)];
lpcoeff = downsampleConv(pad_data,lpfilter,le,n);
hpcoeff = downsampleConv(pad_data,hpfilter,le,n);
%transpose the matrix
data = [lpcoeff hpcoeff]';
%###################### operation on thecolumns###########################
pad_data = [data data(:,1:le)];
lpcoeff = downsampleConv(pad_data,lpfilter,le,n);
hpcoeff = downsampleConv(pad_data,hpfilter,le,n);
%transpose the matrix again
wc = [lpcoeff,hpcoeff]';
return;
%local function
function downsample_coeff = downsampleConv(coeff,filter,le,n)
downsample_coeff = conv2(coeff,filter);
downsample_coeff = downsample_coeff(:, le:2:(le+n -1));
return;
??? Undefined function or variable 'data'.
??? Error: File: necs.m Line: 25 Column: 1
Function definitions are not permitted in this context.
>> I also tried removing the function as illustrated in the example above but still giving an error

类别

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