How to pass from [1x1] to single signal 1 in Simulink?

101 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Guy Rouleau
Guy Rouleau il 6 Mag 2013
To go from [1x1] to 1 and vice-versa, use the Reshape block:
To select form 2:end, use the selector block:
  1 Commento
Dani Tormo
Dani Tormo il 7 Mag 2013
Modificato: Dani Tormo il 7 Mag 2013
Hi Guy,
is there any option to put in the selector block u(2:end)? The size of the vector is changing sometimes and my problem will be solved specifying end.
I cannot see a solution in the documentation.
And about the Reshape block, I cannot change from [1x6] to 6.
Thanks a lot!

Accedi per commentare.

Più risposte (1)

Gijs van Oort
Gijs van Oort il 6 Mag 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 Commento
Dani Tormo
Dani Tormo il 6 Mag 2013
Modificato: Dani Tormo il 6 Mag 2013
Both errors come at the same time. So I think that maybe are related.
I tried to solve the second error with a selector but it didn't work. It keeps the matrix format and I need vector format.
This code was working before without any problem. I am using an M-function and one of its inputs changes depending on a mask in an upper level. For this reason I believe that the problem is by using the submatrix block. The output of this block is a [1x6] or [6x1], and I need a vector format, not an array.
The matter is that I am building a "general" block to connect it in series as many as needed. So the output vector will change because of that. By using a selector inside it keeps the vector format, but I need to use a general notation to discatenate the vector (somehow I need to be able to put v=v(2:end)) in order to not go inside each block and change the selector parameters.
Is there any way to convert a 1-D array into a vector or selecting from a vector from 2:end?
Thank you for your complete question by the way!!

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by