Matlab get stuck when processing large bus
Mostrar comentarios más antiguos
Hello all,
I have a matlab function with a set of busses as inputs. The job of this matlab function is basically to act as a multiplexer. In other words, it has to select an specific bus field from one of the bus inputs and ouput its value. Selection is done using an address input.
In order to select specific bus field, I have a cell matrix that associates address and bus field name in each row.
I have a nested for loop that iterates over all addresses in cell matrix until it finds one that match with input address. Once corresponding row has been found, it iterates over all bus fields until it finds that one whose name matchs with the name stored in the matrix row.
It is something like:
function [output] = selector(bus1,bus2,inputAddress)
output=0; %Default value for output
for i:1:length(numberOfMatrixRows)
%Find address.
if(inputAddress==matrix{i,2}) % Address is stored in second column of matrix
%If address match, then look for corresponding bus field
%Look in bus1
fieldsBus1=fieldnames(bus1);
for u=1:length(fielsBus1)
if(bus1.fieldsBus1{u}==matrix{i,1}) %Field names are stored in first column of matrix
%If bus field name matchs with field name stored in matrix, select that field name value as output
output=bus1.fielsBus1{u};
end
end
%Look in bus2
fieldsBus2=fieldnames(bus2);
for u=1:length(fieldsBus2)
if(bus2.fieldsBus2{u}==matrix{i,1}) %Field names are stores in first column of matrix
%If bus field name matchs with field name stored in matrix, select that field name value as output
output=bus1.fielsBus2{u};
end
end
end
The thing is that if bus 1 and bus2 are small, this is, they have less than 30 elements, this code works well. But when I use large buses, this is for example, 290 elements, Simulink never finnish to compile the model. Do you have any insight about this problem? Thank you for your help.
I would expect that compilation time does not differ for 30 or 300 elements. I do not know why Simulink is not able to process this.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!