Error Message: "Error: Function definitions are not permitted in this context." How do I fix this?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Sarah Wait Zaranek
le 14 Avr 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)
Plus de réponses (1)
Necs
le 23 Mar 2014
Modifié(e) : Necs
le 23 Mar 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 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!