Error Message: "Error: Function definitions are not permitted in this context." How do I fix this?
조회 수: 1 (최근 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!
댓글 수: 0
채택된 답변
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
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!