Error Message: "Error: Function definitions are not permitted in this context." How do I fix this?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason
am 14 Apr. 2011
Bearbeitet: Necs
am 23 Mär. 2014
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 Kommentare
Akzeptierte Antwort
Sarah Wait Zaranek
am 14 Apr. 2011
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)
Weitere Antworten (1)
Necs
am 23 Mär. 2014
Bearbeitet: Necs
am 23 Mär. 2014
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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!