How to pass from [1x1] to single signal 1 in Simulink?
89 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an error and I don't know how to solve it. There are several errors:
- Dimension 1 is fixed on the left-hand side but varies on the right ([1 x 6] ~= [:? x :?]).
- Port width mismatch. Input 'Vref' expects a signal of size 1. The signal received is of size [1x1].
How can I change in simulink from 1x1 to 1?
Thanks!
0 commentaires
Réponse acceptée
Guy Rouleau
le 6 Mai 2013
To go from [1x1] to 1 and vice-versa, use the Reshape block:
To select form 2:end, use the selector block:
1 commentaire
Plus de réponses (1)
Gijs van Oort
le 6 Mai 2013
For answering your first question, we need more information. Please give us (a part of) your model, or describe exactly what you did/need. If this error occurred in a 'Matlab Function' (from the User-Defined Functions library), you probably did not initialize your variable (this must be done in order to be able to compile), or maybe you use 'complicated' equations to calculate the indices on the right hand size of the expression. Matlab needs to be able to calculate the size of the right hand size array at compile time. It can do this using the following code:
lhs_var = zeros(1,6) % initialize left hand size
rhs_hugevar =(1:100) % initialize right hand size var
copyindex = 45
lhs_var = rhs_hugevar(copyindex:copyindex+6)
but it can probably not do this with the following code (note that in some cases you can be sure that the right hand side size is 1x6, but Matlab has no way to know that for sure). (Note also that this code does work in normally interpreted functions in Matlab because it may resize lhs_var if the rhs is not 1x6, but not in codegen functions):
lhs_var = zeros(1,6) % initialize left hand size
rhs_hugevar = (1:100) % initialize right hand size var
copyindex1 = 45
copyindex2 = find(rhs_hugevar==50)
lhs_var = rhs_hugevar(copyindex1:copyindex2)
A solution would be to copy your variable element-by-element. Replace the last line of the previous example by:
for i=1:6
lhs_var rhs_hugevar(copyindex1-1+i);
end;
Alternatively, find a way to write your code such that Matlab can know the size of the rhs on beforehand.
For your second question, consider using a 'Selector' block to select the first element of your one-by-one sized matrix. The selector block is inside the Signal Routing library.
1 commentaire
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!