their something wrong with my script need help please
古いコメントを表示
%the dewpoint function
function Td= dewpoint(T, RH)
%set the a and b values
a = 17.27;
b = 237.7;
%declare the
Td=[];
f=[];
for i=1:length(RH)
%compute f
f(i) = a.*T./(b + T) + log(RH(i));
%copute Td
Td(i) = b.*f(i)./(a-f(i));
end
end
%the my_plot function
function p=my_plots(Td, RH)
%plot and labeling
plot(Td, RH)
title('Mutaz alsomali Dew point plot')
xlabel('Td (F)')
ylabel('RH(%)')
end
%test case1
T=15
RH=0.4
Td= dewpoint(T, RH)
%test case 2
T=35
RH=0.8
Td= dewpoint(T, RH)
figure
%plot for 25
T=25;
RH=0.1:0.05:0.95;
Td= dewpoint(T, RH);
my_plots(Td, RH);
hold on
%plot for 32F
T=(32-32).*5./9;
Td= dewpoint(T, RH);
my_plots(Td, RH);
hold on
%plot for 77F
T=(77-32).*5./9;
Td= dewpoint(T, RH);
my_plots(Td, RH);
hold on
%plot for 95F
T=(95-32).*5./9;
Td= dewpoint(T, RH);
my_plots(Td, RH);
legend('25 C', '32F', '77F', '95F')
hold off
2 件のコメント
Guillaume
2018 年 7 月 5 日
You should tell us what is wrong with your script rather than letting us guess. If you get an error, then give us the full text of the error message (everything in red). If you don't get the result you expected then what did you expect and what did you get instead?
Mutaz Alsomali
2018 年 7 月 5 日
採用された回答
その他の回答 (1 件)
Andrey Porokhnyuk
2020 年 1 月 21 日
編集済み: Andrey Porokhnyuk
2020 年 1 月 21 日
I am moving from Octave, and these restrictions in Matlab are very confusing.
Simply, I had multiple functions in a complex script. When I moved all of them to the end, the interpretter was still throwing this senseless error.
The below-like script throws the same error:
"Error: File: script.m Line: 13 Column: 4
Function definitions in a script must appear at the end of the file.
Move all statements after the "fund" function definition to before the first local function definition.
%% the script code
a=[];
b=[];
c=fund(a,b);
a=fune(a,c);
%functions below
func = @(x, varargin) x(varargin{:});
function a=fund(b,c)
%some code
end;
function a=fune(b,c)
%some code
end;
So, what do you think?
";"
Semicolon!
Matlab has got indigestion from simple semicolon, indicating the silent end of instruction.
No, really, why is it so picky? It is not C++, where {curvies} contain the definition. There are "starting word", and "finishing word" for one declaration/definition. Since it looks like any other instruction, why doesn't it accept semicolon?
2 件のコメント
Rik
2020 年 5 月 13 日
A more pertinent question would also be why a complex script isn't a function in the first place. Using functions in scripts should in my view be considered a rapid prototyping tool or a debugging feature.
Also, mlint will immediatly point you to the location that is the source of the error. Tools like mlint are the reason I personally prefer to program in Matlab and only after that test compatibility in Octave.
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!