mirage
mirage

Reputation: 145

Calling function with changing input parameters in a loop Matlab

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

Upvotes: 0

Views: 2044

Answers (1)

George Skoptsov
George Skoptsov

Reputation: 3951

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

Upvotes: 1

Related Questions