Questions tagged [stateflow]

StateFlow is a toolbox from MathWorks for development of state machines. For questions regarding the StateFlow interface from Kotlin's kotlinx.coroutines library, use the [kotlin-stateflow] tag instead.

Stateflow is an toolbox (extension) of Matlab from Mathworks. It is a commercial, and proprietary toolset.

Generally, Stateflow extends Simulink with the ability to design and test state machines. It is commonly used in control design, where algorithms can be either MATLAB scripts & formulas, Simulink blocks or embedded code (in the form of so-called S-functions).

Code generation is supported on the host platform, but for target code additional tools are required (such as Simulink Real-Time (previously known as real time Workshop) or Embedded Coder).

Advantages compared to software-only tooling (like IBM Rhapsody):

  • use with hardware (in the loop)
  • seamless integration with Simulink

Disadvantages compared to software-only tooling:

  • high license cost for code generation

Links:

131 questions
24
votes
8 answers

Unit testing/continuous integration with Simulink/Stateflow

How can I perform unit testing in Simulink, or preferably, Stateflow? I'm a fan of agile software methods, including test driven development. I'm responsible for the development of safety critical control software and we're using…
Adriaan
  • 3,282
  • 1
  • 23
  • 31
20
votes
2 answers

Kotlin combine more than 2 flows

I'm looking to combine 4 StateFlow values and make 1 StateFlow from these. I know already of the combine function like this: val buttonEnabled = cameraPermission.combine(micPermission) { //some logic } How could this be done with 4 flows? when…
alfietap
  • 1,585
  • 1
  • 15
  • 38
18
votes
2 answers

mutableState VS mutableStateFlow?

I'm confused, can someone explain to me, what's the main difference between those two? I'm having hard times understanding. mutableState was introduced with Jetpack Compose, and now my question is, should we use it in a View Model as a replacement…
Stefan
  • 2,829
  • 5
  • 20
  • 44
17
votes
1 answer

Android MVI using StateFlow and paging 3

I am trying to implement android MVI architecture using state flow and paging 3 but I got confused when I had a view state which contains paging data. The problem is that I expose the view state from view model as a state flow object, but now inside…
17
votes
4 answers

Collect from several stateflows

I have 2 stateFlow's in my viewModel. To collect them in fragment I have to launch coroutines 2 times as below: lifecycleScope.launchWhenStarted { stocksVM.quotes.collect { if (it is Resource.Success) { …
Azim Salimov
  • 305
  • 1
  • 3
  • 13
15
votes
1 answer

What are the differences between StateFlow and LiveData?

as I mentioned in the title, I'm curious about the general differences between the two. Can you help with this? I couldn't find the specific differences as there are complex examples on the internet. What are the differences in terms of…
Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
9
votes
1 answer

how to avoid repeatOnLifecycle excute again and again when fragment resume

how can I avoid the collect{} code execute again when navigate back to the fragment. ViewModel class private val _commitResult = MutableStateFlow>(mapOf()) val commitResult: StateFlow> =…
Freddy
  • 764
  • 2
  • 6
  • 21
8
votes
7 answers

What's the difference between stateflow and simulink?

As far as I know, stateflow and simulink are often used at the same time, and are both environments developed by MathWorks, who make Matlab. May I know what's the difference between them?
user1487718
6
votes
4 answers

How to init a sealed-class in MutableStateFlow

I have a sealed-class like this sealed class LoadState { class Loading : LoadState() class Success : LoadState() class Fail : LoadState() } I use sealed-class with LiveData, it works open class BaseViewModel: ViewModel() { // val…
kokod21
  • 61
  • 1
  • 2
5
votes
1 answer

How to print size of flow in kotlin

Hey I am new in kotlin flow. I am trying to print flow size. As we know that list has size() function. Do we have something similar function for flow. val list = mutableListof(1,2,3) println(list.size) output 2 How do we get size value in…
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
4
votes
3 answers

MutableStateFlow not working with MutableList

Here is my MutableStateFlow value I try to work with: val songList: MutableStateFlow> = MutableStateFlow(arrayListOf()) I need to observe changes (after methods like add, removeAt etc.) on my MutableList above but can't achieve…
4
votes
2 answers

Update Kotlin StateFlow without change emitting

Is it possible to update Kotlin StateFlow without emitting the change? The use case is that when user zooms a chart view, I would like to have that restored when activity resumes but skip the StateFlow events while zooming is in progress.
yaugenka
  • 2,602
  • 2
  • 22
  • 41
4
votes
1 answer

How many Stateflows can I observe at one time?

I develop apps for Android. I was wondering how many Kotlin Stateflows can I observe at one time? Every observe that I do is done on different CoroutineScope created by myself, dispatched by IO dispatcher or provided by lifecycle components of…
4
votes
2 answers

Programmatically open a Simulink MATLAB function block's code

Can I open a local Simulink MATLAB function block's code in the MATLAB editor via some command? For example, let us say I have a Simulink model named mainModel.slx. In it, there is a MATLAB function block named localFunction. This is not defined in…
Smartskaft2
  • 468
  • 3
  • 16
3
votes
2 answers

Prevent replay of StateFlow after returning from another Activity

I've an Activity A, with it's ViewModel with StateFlow UI State implementation as said in Android's documentation. class A_ViewModel: ViewModel() { private val _uiState = MutableStateFlow(UIState.None) val uiState: StateFlow =…
Suraj Kumar Sau
  • 438
  • 6
  • 10
1
2 3
8 9