2 equations in one function matlab
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Hello,
when i write this code in matlab it only gives me the value for the Area A and not the circumference C. What did I do wrong? Thanks 
function [A,C]= myfunction(radius)
radius=2.45;
A=pi*(radius^2);
C=2*pi*radius;
end
0 Kommentare
Akzeptierte Antwort
  Jon
      
 am 18 Jan. 2021
        When you called it did you call it with two output arguments? e.g.
radius = 5
[A,C] = myfunction(radius)
Also, you reassign the radius a value of 2.45 inside of the function, so it will not actually use the value of the radius supplied as an argument. I assume that this is not what you intended
2 Kommentare
  Jon
      
 am 18 Jan. 2021
				You have to put this part into a separate file and save it as myfunction.m
function [A,C]= myfunction(radius)
A=pi*(radius^2);
C=2*pi*radius;
end
Then from the command line you can type
>radius = 2.45
>[A,C] = myfunction(radius)
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Logical 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!

