Error of Ploting the contour that satisfies a condition

조회 수: 1 (최근 30일)
Tin Truong Chanh
Tin Truong Chanh 2024년 3월 11일
댓글: Voss 2024년 3월 12일
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
  댓글 수: 2
Tin Truong Chanh
Tin Truong Chanh 2024년 3월 12일
it works well, thank you so much for your help.
Voss
Voss 2024년 3월 12일
You're welcome!

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

추가 답변 (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