在一个循环中改变输入参数调用函数 [英] Calling function with changing input parameters in a loop Matlab

查看:103
本文介绍了在一个循环中改变输入参数调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我知道它并不困难,但我不知道如何实现它。我有一个m文件,看起来像

  clear; 
PVinv.m_SwF = 20e3

for m = 1:1:70;

PVinv.m_SwF = PVinv.m_SwF + 1e3;
Lmin = PVinv.InductanceDimens();
Wa_Ac = PVinv.CoreSizeModel();
PVinv.CoreSelect(Wa_Ac);
[loss_ind_core,loss_ind_copper] = PVinv.InductorLossModel(PVinv.m_L_Selected);
Total_Inductor_Loss = loss_ind_core + loss_ind_copper
plot(PVinv.m_SwF,Total_Inductor_Loss,' - gs');
持有
xlim([10e3 90e3])
set(gca,'XTickLabel',{'10';'20';'30';'40';'50'; '60';'70';'80';'90'})
grid
xlabel('Switching Frequency [kHz]');
ylabel('Power loss [W]');




$ b $ p
$ b $ p $感兴趣的函数是CoreSelect(Wa_Ac)

  function obj = CoreSelect(obj,WaAc)
obj.m_Core_Available = obj.m_Core_List(i);
obj.m_L_Selected.m_Core = obj.m_Core_Available;

end

我想将ob的值从obj.m_Core_List (1)到主m文件的循环内的obj.m_Core_List(27)。当我在主m文件
中调用函数coreselect时,如何获取函数coreselect的值例如,对于m = 1到70,我希望函数采用i = 1的值,然后执行直到绘图命令with but i = 2等等
任何建议都会很有帮助

解决方案

我不知道我明白你的问题完美,但我想你想要传递一个索引 CoreSelect 函数,循环 i 从1到27之外的函数。试试这个:
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

为i = 1:27,
PVInv.CoreSelect(WaAc,i);
end


I have caught myself in a issue, I know its not that difficult but I couldnt figure out how to implement it. I have an m file that looks like

clear;
PVinv.m_SwF=20e3

for m=1:1:70;  

PVinv.m_SwF=PVinv.m_SwF+1e3;
Lmin = PVinv.InductanceDimens();
Wa_Ac = PVinv.CoreSizeModel();
PVinv.CoreSelect(Wa_Ac);   
[loss_ind_core,loss_ind_copper] = PVinv.InductorLossModel(PVinv.m_L_Selected);
Total_Inductor_Loss=loss_ind_core+loss_ind_copper
plot(PVinv.m_SwF,Total_Inductor_Loss,'--gs');
hold on
xlim([10e3 90e3])
set(gca,'XTickLabel',{'10';'20';'30';'40';'50';'60';'70';'80';'90'})
grid on
xlabel('Switching Frequency [kHz]');
ylabel('Power loss [W]');

end

And the function that is of interest is CoreSelect(Wa_Ac)

function obj = CoreSelect(obj, WaAc)
             obj.m_Core_Available= obj.m_Core_List(i);
            obj.m_L_Selected.m_Core = obj.m_Core_Available;

end 

I want to change the value of i from obj.m_Core_List(1) to obj.m_Core_List(27) within that for loop of main m file. How can I get the value of the function coreselect when I call it in main m file For eg for m=1 to 70 I want the function to take the value of i=1 then execute till plot command and then same with but i=2 and so on Any suggestion would be really helpful

解决方案

I'm not sure I understand your question perfectly, but I think you want to pass an index i to the CoreSelect function, and loop i from 1 to 27 outside of the function. Try this:

function obj = CoreSelect(obj, WaAc, i)
...
end

for i=1:27,
   PVInv.CoreSelect(WaAc,i);
end

这篇关于在一个循环中改变输入参数调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆