How to convert signal data type by using function or code script

7 visualizaciones (últimos 30 días)
杰林
杰林 el 5 de Jul. de 2024
Comentada: Umar el 5 de Jul. de 2024
Is there a function or code script to change the signal data type of signal editor InputScenario in test harness like the following picture shows:

Respuesta aceptada

Umar
Umar el 5 de Jul. de 2024
Hi 杰林,
By assigning the fixdt(1,16,4) to a new data type, such as double, you can effectively convert the data type in the Signal Editor InputScenario. For example,
% Define the fixed-point data type
dt = fixdt(1,16,4);
% Convert the data type to another type, for example, double
new_dt = double(dt);
Hope this helps.
  2 comentarios
杰林
杰林 el 5 de Jul. de 2024
Editada: 杰林 el 5 de Jul. de 2024
Hi Umar,
Thanks a lot, I want to convert the double data type to the fixed-point data type, is there a method to achieve this goal?
Umar
Umar el 5 de Jul. de 2024
Hi 杰林,
by using the Fixed-Point Tool, you can convert a double data type to a fixed-point data. By using the fi function, you can specify the word length and fraction length for the fixed-point representation. This allows you to convert your double data type to a fixed-point representation in Matlab's Signal Editor.

Iniciar sesión para comentar.

Más respuestas (2)

Umar
Umar el 5 de Jul. de 2024
Hi 杰林,
If I understand your question correctly, when working with Simulink Test Harnesses and the Signal Editor, there are ways to change the signal data type within the InputScenario. The InputScenario allows you to define input signals for your test cases, including specifying the data type of these signals.To change the signal data type in the Signal Editor InputScenario, you can follow these steps:
Accessing the Signal Editor:
Open your Simulink model. Navigate to the "Apps" tab and click on "Simulink Test" to open the Simulink Test Manager. In the Simulink Test Manager, select your test file that contains the test harness.
Modifying Signal Data Type:
Within the test file,locate the test harness that contains the InputScenario you want to modify. Double-click on the InputScenario block to open the Signal Editor. In the Signal Editor, you can modify the properties of the signals, including the data type.
Changing Data Type:
To change the data type of a signal, select the signal in the Signal Editor. In the properties pane, you can change the data type to the desired type (e.g., double, int8, uint16, etc.).Save your changes in the Signal Editor.
Verifying Changes:
After modifying the data type, ensure that the changes are reflected correctly in your test harness. You can run your test cases to verify that the signal data type modifications are functioning as expected.
By following these steps, you can effectively change the signal data type within the Signal Editor InputScenario in a test harness. This allows you to customize the data types of input signals for your test cases, ensuring accurate testing and validation of your Simulink models.
  1 comentario
杰林
杰林 el 5 de Jul. de 2024
Hi Umar,
Very thanks. I want to run the test harness by .m script, input data from excel table, so I want to change the data type by using a code script like the effect that I change the data type by click in the botton.

Iniciar sesión para comentar.


Umar
Umar el 5 de Jul. de 2024
Hi 杰林,
You can change data types programmatically using functions like double(), single(), int8(), int16(), int32(), int64(), uint8(), uint16(), uint32(), uint64(), logical(), char(), etc. To achieve the effect of changing data types dynamically in a script, you can use these functions to convert data types as needed. For example, if you have a variable myData that you want to convert to a different data type, you can do so like this:
% Convert myData to int32
myData = int32(myData);
By incorporating these type conversion functions into your script, you can achieve the desired effect of changing data types programmatically, similar to interacting with a button in the interface.
  1 comentario
杰林
杰林 el 5 de Jul. de 2024
Hi Umar,
This method can cover most situations. How can I convert the data type of fixdt(1,16,4)?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by