필터 지우기
필터 지우기

In Simulink how would you change [4x1] signal to [1x1]

조회 수: 5 (최근 30일)
Adam s
Adam s 2021년 7월 19일
댓글: Walter Roberson 2021년 7월 19일
I would like to take a signal in simulink for example a =123 and b = 456 and have the output = 123456.
How would you do this?

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 19일
Arithmetic blocks? One that multiplies by 1000 and the other that adds ?
Or is the range of values not set in advance? Is the range variable? For example if one time a = 123 b = 456 then you want 123456 as output; if the next time a = 123 and b = 45 then would you want 12345 as output, or would you want 123045 as output?
What result do you want if one of the values is negative? If both of them are negative then do you need a negative result?
  댓글 수: 3
Adam s
Adam s 2021년 7월 19일
I will never have a negative number the lowest the values can go is zero.
Walter Roberson
Walter Roberson 2021년 7월 19일
2 (constant block) ->
| max (minmax block) --> [T1]
B ->
[T1] ->
| multiply (product block) -> log10 (math block) -> [T2]
(1+20*eps) (constant block) ->
[T2] -> ceiling (rounding function) -> 10^u (math) ->
| multiply (product block) -> [T3]
A ->
[T3] ->
| add (math) --> result
B ->
In the above, I give an operation name, and then in () I give the name of the block that implements it.
In the above, the [T1] are not operations, but are simply labels to make clearer how the blocks join together
So you take
A * 10^ceil(log10((1+20*eps)*max(B,2))) + B
The max() part is to handle 0 and 1 the same as 2 to 9.
The 1+20*eps part is a hack so that exact powers of 10 such as 1000 get the full number of digits, since ceil(log10(99)) is 2, same as ceil(log10(100)). The constant 20*eps is sufficient up to 1E32... but of course if you are above 1E15 then you have to start worrying about losing precision when you do the concatenation.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sameer Pujari
Sameer Pujari 2021년 7월 19일
You can do this
  댓글 수: 2
Adam s
Adam s 2021년 7월 19일
편집: Walter Roberson 2021년 7월 19일
Yes, techinally that works for the example given. However if the math is not the easy how would you do it?
Such as in matlab you can do:
a = 1;
b= 2;
c=3;
str = sprintf(%d%d%d, a,b,c)
double = str2double( str)
dobule = 123
How do you do this in Simulink?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by