## Take your ideas beyond research to production

### Some examples of what we do

Build Apps in MATLAB with App Designer

### Optimize code making it easier to understand

```load('patients.mat')
Gender = categorical(Gender);
GenderList = unique(Gender);
for idx = 1:length(GenderList)
idxHeight = Height(Gender==GenderList(idx));
HeightAvg(idx) = mean(idxHeight)
end```

vs

```load('patients.mat')
byGroup = findgroup(byGender);
HeightAvg = splitapply(@mean, Height, byGroup)
```

The example above shows the usage of two built-in MATLAB functions findgroup and splitapply that make the code easier to read and maintain.

```function out = myFunction(A, B, C)
arguments
A (1,1) string
B (1,:) double
C (2,2) cell
end

% Function code
% ...
end
```

The example is using arguments that was released in R2019b to help with function argument validation. It makes the code easier to read and it validates input variables on size and type.

### Refactor code to make it easier to reuse

```def censor(text,word):
while word in text:
text = text[:text.find(word)] + "*"*len(word) +
text[text.find(word) + len(word):]
return text
```

vs

```def censor(text, word):
censor_string = '*' * len(word)
return censor_string.join(text.split(word))```

Notice that the while loop was not necessary in the example above. It is hard to understand quickly the first code snippet where is the second makes it clear that the function replaces a particular word with *’s in the text provided.

```import matlab.engine
eng = matlab.engine.start_matlab()
tf = eng.isprime(37)
print(tf)```

The example shows how to invoke MATLAB from Python. It is also possible to invoke Python from MATLAB.