Azzera filtri
Azzera filtri

How can i create a loop using Simulink blocks, to do multiple iterations with some arithmetic operations and output correct answer.

1 visualizzazione (ultimi 30 giorni)
Please help me this is urgent. I have model which required data from a lookup table and in same time the indexes of the lookup table should be found inside the model. it consist with multiple number of defferential equations, the equations result should be go to a logic/ function and that function/ logic requires data from lookup table, then function/ logic need to select correct point and output it into the model while the model is running.
this is the matlab code i created for above operation, i need this to implement using Simulink? can someone help me Please........(in simulink, excel files are not executing so i have prepared a lookup table containing same data.)
function T = fcn(X1,X2,X3,)
Excel_File_2 = readtable('Bubble_Point_Lookup.xlsx');
for a = 2:871
P1 = Excel_File_2{a, 6};
P2 = Excel_File_2{a, 9};
P3 = Excel_File_2{a, 14};
%K1 = str2double(k1);
%K2 = str2double(k2);
%K3 = str2double(k3);
Y1 = P1 * X1;
Y2 = P2 * X2;
Y3 = P3 * X3;
Sum_Yi=Y1+Y2+Y3;
if Sum_Yi>1
disp(a)
KT = Excel_File_2{a, 1};
disp(KT)
break;
end
end

Risposte (1)

Shubh Pareek
Shubh Pareek il 11 Giu 2023
From what i have understood ,u want a Simulink model for this Matlab function .
maybe be this method can help ,
create a function block of this Matlab code in Simulink in a subsystem .
first set architecture of your Matlab function in Matlab Datapath.
path_to_func = 'file_name/subsytem_name/function_block_name';
hdlset_param(path_to_func, 'Architecture', 'MATLAB Datapath')
then call makehdl on this subsystem
makehdl('file_name/subsytem_name')
Then in the current directory you are working inside the hdlsrc folder there will be a folder named with the Simulink file you were working with ,and in that folder there will be .slx file generated with a prefix 'gm_' in the name,
That is a generated equivalent simulink model for what you implemented in the Simulink , when you open this model, inside the subsytem you will be able to see how this function is implemented in Simulink .
I hope this helps your query .
Some resources for the commands mentioned -
  3 Commenti
Shubh Pareek
Shubh Pareek il 12 Giu 2023
Actually for using the makehdl command we need a subsystem , so just double click inside simulink and type subsytem and open that subsytem ,then inside it create a MATLAB function block(it is also there in the picture you shared ) for writing what you have implemented .
also you don't need to find MATLAB datapath ,in the command i mentioned you just need to change the path_to_func variable according to the names of your files and subsystem .
also change the name inside makehdl command , i kept it like that since i didn't know the respective names .

Accedi per commentare.

Categorie

Scopri di più su Modeling in Help Center e File Exchange

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by