Error of Ploting the contour that satisfies a condition

1 次查看(过去 30 天)
Helle everyone,
I am struggling a bit with a Matlab program that I am writing. I am supposed to create a contour of value with the condition :
From this plot
I want to use the condition the value
M_buck(M_buck > 1 ) = 0.0 ;
M_boost(M_boost < 1) = 0.0 ;
However, only second case (M_boost(M_boost < 1) = 0.0 ;) is working well, the first case have the error in the line as shown
Thank you so much for your support.
Here the the code:
clear all
close all
clc
Vo_max = 400;
Pout = 1000;
fs = 50e3;
Ts =1/ fs; % half of switching perior
T = 0.5 * Ts;
L = 50e-6;
Io =Pout / Vo_max;
n = 0.5;
R = Vo_max / Io;
k = ( T .* R )./ ( n.^2 .* L );
D = linspace( 0,0.5 , 100 );
D_buck= linspace( 0.0, 0.5, 1000);
D_boost= linspace( 0.0, 0.5, 1000);
M_buck = D_buck .* ( 1 - D_buck ) .* k;
M_boost = D_boost .* ( 1 - D_boost ) .* k;
% condition
M_buck(M_buck > 1 ) = 0.0 ;
M_boost(M_boost < 1) = 0.0 ;
[ D_lamda_buck , M_lamda_buck ] = meshgrid ( D_buck , M_buck );
[ D_lamda_boost , M_lamda_boost ] = meshgrid (D_boost , M_boost );
lamda_buck = ( ( 2 .* D_lamda_buck -1 ) + M_lamda_buck) .^2 ./ (( 8 .* D_lamda_buck .* ( 1 - D_lamda_buck ) .* ( M_lamda_buck +1) ) );
lamda_boost =( ( 2 .* D_lamda_boost -1 ) +1./M_lamda_boost ).^2 ./ (( 8 .* D_lamda_boost .* ( 1 - D_lamda_boost ) .* ( 1./M_lamda_boost +1) ) );
%% Plot figures
figure (1)
hold on
[C_buck ,h_lamda_buck]=contour(D_lamda_buck,M_lamda_buck,lamda_buck,[ 0.01 0.05 0.1 0.2 0.25 ], 'color','b');
clabel(C_buck,h_lamda_buck)
[C_boost ,h_lamda_boost]=contour(D_lamda_boost,M_lamda_boost,lamda_boost,[ 0.01 0.05 0.2 0.25 ],'color','r');
clabel(C_boost,h_lamda_boost)
axis([0 0.5 0.5 1.5])
xlabel(' D');
ylabel('M')
grid on
hold off

采纳的回答

Voss
Voss 2024-3-11
Does using NaN instead of 0 give the desired result? See below.
clear all
close all
clc
Vo_max = 400;
Pout = 1000;
fs = 50e3;
Ts =1/ fs; % half of switching perior
T = 0.5 * Ts;
L = 50e-6;
Io =Pout / Vo_max;
n = 0.5;
R = Vo_max / Io;
k = ( T .* R )./ ( n.^2 .* L );
D = linspace( 0,0.5 , 100 );
D_buck= linspace( 0.0, 0.5, 1000);
D_boost= linspace( 0.0, 0.5, 1000);
M_buck = D_buck .* ( 1 - D_buck ) .* k;
M_boost = D_boost .* ( 1 - D_boost ) .* k;
% condition
M_buck (M_buck > 1) = NaN ;
M_boost(M_boost < 1) = NaN ;
[ D_lamda_buck , M_lamda_buck ] = meshgrid ( D_buck , M_buck );
[ D_lamda_boost , M_lamda_boost ] = meshgrid (D_boost , M_boost );
lamda_buck = ( ( 2 .* D_lamda_buck -1 ) + M_lamda_buck) .^2 ./ (( 8 .* D_lamda_buck .* ( 1 - D_lamda_buck ) .* ( M_lamda_buck +1) ) );
lamda_boost =( ( 2 .* D_lamda_boost -1 ) +1./M_lamda_boost ).^2 ./ (( 8 .* D_lamda_boost .* ( 1 - D_lamda_boost ) .* ( 1./M_lamda_boost +1) ) );
%% Plot figures
figure (1)
hold on
[C_buck ,h_lamda_buck]=contour(D_lamda_buck,M_lamda_buck,lamda_buck,[ 0.01 0.05 0.1 0.2 0.25 ], 'color','b');
clabel(C_buck,h_lamda_buck)
[C_boost ,h_lamda_boost]=contour(D_lamda_boost,M_lamda_boost,lamda_boost,[ 0.01 0.05 0.2 0.25 ],'color','r');
clabel(C_boost,h_lamda_boost)
axis([0 0.5 0.5 1.5])
xlabel(' D');
ylabel('M')
grid on
hold off

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by