Effacer les filtres
Effacer les filtres

Plotting graphs with functions in if loop

1 vue (au cours des 30 derniers jours)
Sushant Singh
Sushant Singh le 24 Fév 2021
Commenté : Sushant Singh le 24 Fév 2021
Hello community
I want to plot the graph of fb (on Y-axis) vs x (on X-axis) for the attached code:
The plot that I get is also attached here. As I am new to MATLAB I am sure there are mistakes. Any help will be greatly appreciated.
clear all,
clc,
P=93000 ;
L=45*10^(-3);
x= linspace(0,58*10^(-6));
sx=(P/L).*(x);
sY=22;
n=0.53 ;
K=3.9 ;
if sY<sx
fb=(sx.^-1).*((sx-sY)/K).^(1/n);
else
fb=0;
end
plot(x,fb,'-o')
Regards
Sushant

Réponse acceptée

Matteo Pellegri
Matteo Pellegri le 24 Fév 2021
Modifié(e) : Matteo Pellegri le 24 Fév 2021
You are using the if condition in the wrong way. You can perform you calculation first and then use array index to set the values of fb to 0 right after.
clear all
clc
P=93000 ;
L=45;
x= linspace(0,58,100);
sx=(P/L)*(x); %for scalar multiplication you don't need the .
sY=22;
n=0.53 ;
K=3.9 ;
fb=(sx.^-1).*((sx-sY)/K).^(1/n);
fb(sx<=sY)=0;
plot(x,fb,'-o')
  1 commentaire
Sushant Singh
Sushant Singh le 24 Fév 2021
Thank you very much!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by