フィルターのクリア

function defintion

2 ビュー (過去 30 日間)
shafagh
shafagh 2011 年 8 月 22 日
hi may be some body can correct me ? well i have matlab 2011 and try to define a function but the as i define the function as i get the remark that
??? Error: File: raman.m Line: 6 Column: 1 Function definitions are not permitted in this context.
i have no idea why
;clear;
Rd=load('A1.txt')
plot(Rd);
hold on;
[m,n]=size(Rd);
function [r] =uigetfile(Rd)
for i=1:m
y=(1/2*pi)*(w(i)^2)/(x-x(i))^2+w(i)^2
end
end

採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 22 日
Naming your own function as "uigetfile" is not a good idea. You are going to greatly confuse anyone who tries to read your code.
You are going to have difficulties because your function declares that it computes a result named "r", but you do not in fact compute that result.
The result you do compute, "y", you throw away -- local variables are not saved when the function exits.
You also have a problem because at each iteration of your loop, you overwrite the same "y".
You have another problem because your function relies on "x" and "w", but neither of those are defined at the time of execution.
And of course you have the problem that although you define the function, you never call it.
  1 件のコメント
shafagh
shafagh 2011 年 8 月 23 日
if you could please explain me the correct way of defining a function.

サインインしてコメントする。

その他の回答 (1 件)

Chirag Gupta
Chirag Gupta 2011 年 8 月 22 日
You cannot define MATLAB functions in the middle of a script.
function myscript
clear;
Rd=load('A1.txt')
plot(Rd);
hold on;
[m,n]=size(Rd);
function [r] =uigetfile(Rd)
for i=1:m
y=(1/2*pi)*(w(i)^2)/(x-x(i))^2+w(i)^2
end
end
  2 件のコメント
shafagh
shafagh 2011 年 8 月 23 日
how do i that ( define the function ) then? i m new and try to learn matlab thats why i cant know it !
Walter Roberson
Walter Roberson 2011 年 8 月 23 日
Just like Chirag shows. Your sticking point at the moment is that it is not allows to define a function in the middle of a script. A "script" in MATLAB is a code file whose first non-comment line does *not* start with the word "function". Chirag's version DOES start with "function", and so is a MATLAB Function file rather than a MATLAB "script".
Of course once you have that issue solved you will need to solve the other issues that I mentioned in my response.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by