Borrar filtros
Borrar filtros

Help with script and function

3 visualizaciones (últimos 30 días)
Milad Ahmed
Milad Ahmed el 14 de Abr. de 2018
Editada: Milad Ahmed el 14 de Abr. de 2018
For my soil mechanics lab I need to plot three Mohr Circle on the same axes. I need help on making this function take any input(s3,s1) (instead of assigning a value to s3 and s1 in the script) and returning the radius of the circle.
function [r,h]= geotech_mohrcirc(s3,s1)
clear all
close all
clc
s3= 50;
s1= 103.169;
x=linspace(s3,s1,1000);
r=(s1-s3)/2;
h=(s1+s3)/2;
y=abs(sqrt(r^2-(x-h).^2));
plot (x,y)
axis equal
grid on
axis([0,s1+r,0,1.25*r])
xlabel('Normal stress \sigma_n (kPa)')
ylabel ('Shear stress \tau (kPa)')
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Abr. de 2018
Get rid of the "clear all". Once you do that then you can remove the assignments from the script. The "clear all" is erasing the parameters that are passed in.
I also recommend getting rid of the "close all" and "clc".
  2 comentarios
Rik
Rik el 14 de Abr. de 2018
The inclusion of clear all,close all,clc is a prime example of cargo cult programming. If you don't actually need to clear everything, don't use clear all. If you want to clear variables in a script, use clearvars instead at the very least. M-lint also generates a warning for this. You should really try to resolve every warning. You can suppress warnings you decide not to resolve by including %#ok after that line. That way, you can easily keep track of any new warnings.
Milad Ahmed
Milad Ahmed el 14 de Abr. de 2018
Editada: Milad Ahmed el 14 de Abr. de 2018
Thank you !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by