How to use interp1 command?

11 ビュー (過去 30 日間)
Mohammed Alharbi
Mohammed Alharbi 2021 年 9 月 26 日
編集済み: Mohammed Alharbi 2021 年 10 月 4 日
I have the code to draw each of these 6 figures as follows:
ph1 = 1;
ph2 = 2;
ph3 = 3;
ph4 = 4;
ph5 = 5;
ph6 = 6;
Vi=30;
Vo=0:0.1:30;
d= Vo./Vi ;
m1= d*ph1;
m2= d*ph2;
m3= d*ph3;
m4= d*ph4;
m5= d*ph5;
m6= d*ph6;
floor1= floor(m1);
floor2= floor(m2);
floor3= floor(m3);
floor4= floor(m4);
floor5= floor(m5);
floor6= floor(m6);
Kcm1 = (1-(floor1./(ph1*d))).*(1+floor1-ph1*d)
Kcm2 = (1-(floor2./(ph2*d))).*(1+floor2-ph2*d)
Kcm3 = (1-(floor3./(ph3*d))).*(1+floor3-ph3*d)
Kcm4 = (1-(floor4./(ph4*d))).*(1+floor4-ph4*d)
Kcm5 = (1-(floor5./(ph5*d))).*(1+floor5-ph5*d)
Kcm6 = (1-(floor6./(ph6*d))).*(1+floor6-ph6*d)
figure (1)
hold on
title('for the output current ripple')
xlabel('Duty Cycle')
ylabel('Kcm')
plot(d,Kcm1)
plot(d,Kcm2)
plot(d,Kcm3)
plot(d,Kcm4)
plot(d,Kcm5)
plot(d,Kcm6)
legend('Phase1','Phase2','Phase3','Phase4','Phase5','Phase6');
grid on
hold off
What I want to do is that based on an input value (which is going to be a value on the X-axis), I want the output to choose the figures out of these 6 figures that give the minimum Y-axis value.
For example,
If I put the input value to be 0.5, which is a duty cycle value on the X-axis, then the output should display and recommend (phase-2, phase-4 and figure 6) as they give the minimum value of Y-axis (exactly 0) at this specific input value of 0.5
Another example,
If the input value is 0.25, then the recommend figure to be displayed is (phase-4 the yellow one) as this also gives the minimum value on the Y-axis, and so on.
I was told that I could use the "interp1" command for each curve and pick the minimum but I don't know how to use it.
Please help me out?

採用された回答

Stephen
Stephen 2021 年 9 月 27 日
編集済み: Stephen 2021 年 9 月 27 日
Numbering your variables like that is a red-herring that makes this task more complex.
MATLAB is designed to work efficiently with arrays. Using arrays makes your code much simpler:
ph = 1:6;
Vi = 30;
Vo = 0:0.1:30;
d = Vo./Vi;
m = d(:).*ph; % note the orientation!
Kcm = (1-(floor(m)./m)).*(1+floor(m)-m);
figure (1)
title('for the output current ripple')
xlabel('Duty Cycle')
ylabel('Kcm')
plot(d,Kcm)
legend(sprintfc('Phase%d',ph));
grid on
Using arrays also makes your task much simpler:
inp = 0.5;
tmp = interp1(d,Kcm,inp);
idx = find(tmp==min(tmp))
idx = 1×3
2 4 6
inp = 0.75;
tmp = interp1(d,Kcm,inp);
idx = find(tmp==min(tmp))
idx = 4
Note that the orientation of the data in m is significant, because INTERP1 treats each column as its own dataset.
  12 件のコメント
Mohammed Alharbi
Mohammed Alharbi 2021 年 10 月 4 日
Hi Stephen,
I sloved the previous issue by putting
m = d'*ph;
instead of:
m = d(:).*ph;
But now I have another issue with using the "find" command in Simulink function block as it always returns a variable-length vector. Please have a look at this thread if you have time, I am sure you will be the one who can hlep me out with this
Thannks in advance!
Mohammed

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by