Trying to use function ,didnt work?

조회 수: 3 (최근 30일)
Bastian
Bastian 2023년 12월 12일
편집: Matt J 2023년 12월 12일
function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
when i typed it like this it gave me error sayin to type the function part like so and i dont understand why
function [Delta]= finddeflexion(~)
the code then works fine
  댓글 수: 2
Mann Baidi
Mann Baidi 2023년 12월 12일
Why are you having "Length" as function parameter?
Bastian
Bastian 2023년 12월 12일
not sure what you mean by function parameter

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2023년 12월 12일
when i typed it like this it gave me error
I doubt it gave you an error. It certainly doesn't give me one.
You probably got a Code Analyzer warning saying that the input argument "Length" is not being used. If you want it to be used remove the line which overwrites it:
function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
%Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
end
  댓글 수: 10
Bastian
Bastian 2023년 12월 12일
if you look at these images you will understand what i am trying to say
i want it s when i run it it displays as so
[Delta]= finddeflexion(Length)
and then let me the user type in the value for length
in first screen shot i have underlined what i mean by options when running, it seems that i have to put in value first like so, instead of just pressing run and changing the value of length in command window
Matt J
Matt J 2023년 12월 12일
편집: Matt J 2023년 12월 12일
instead of just pressing run and changing the value of length in command window
Yes, we removed the line where you are prompted for the Length from the command window.
If you want to set the Length variable in the command window, then you should put that line back in, but remove "Length" from the function signautre line
function [Delta]= finddeflexion() %or finddeflexion(~)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
Length = input(prompt); %<--- put this line back in
Delta = W*(Length^3)/(8*E*I);
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by