Metadata-Version: 2.4
Name: matlabtopython-compat
Version: 0.1.0
Summary: MATLAB compatibility helpers for Python code converted by matlabtopython.com
Author: Robert Batt
License: MIT
Project-URL: Homepage, https://mtopython.com
Project-URL: Repository, https://github.com/RobDBatt/matlabtopython-compat
Keywords: matlab,migration,numpy,compatibility
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy>=1.20
Provides-Extra: mat-io
Requires-Dist: scipy>=1.7; extra == "mat-io"

# matlabtopython-compat

Runtime helpers for Python code converted from MATLAB by
[matlabtopython.com](https://mtopython.com).

When the converter emits a construct that has no clean numpy/scipy
equivalent — cell arrays, struct field access, sprintf with vector
expansion, column-major flatten — it imports from this package.

## Install

```bash
pip install matlabtopython-compat
```

Optional `.mat` file I/O adds a scipy dependency:

```bash
pip install "matlabtopython-compat[mat-io]"
```

## What's in it

| Helper | MATLAB equivalent | Why it's here |
|---|---|---|
| `CellArray` | `c = {a, b, c}` | Lists work for most cells but miss `c{1} = ...` grow-on-write semantics. |
| `Struct` | `s.name`, `s.(name)` | Combines attribute + dict access in one object. |
| `sprintf` | `sprintf('%d\n', [1 2 3])` | Vector arguments cycle through format specifiers — Python's `%` doesn't. |
| `fprintf` | `fprintf(fid, fmt, args)` | Same, with file-handle form. |
| `tic` / `toc` | `tic; ... toc` | MATLAB-compatible timing output. |
| `flatten_fortran` | `X(:)` | Column-major flatten (numpy defaults to row-major). |
| `sort_with_index` | `[s, i] = sort(X)` | Returns both sorted values and indices. |

## Example

```python
from matlabtopython_compat import CellArray, Struct, sprintf, tic, toc

# Cells with grow-on-write
c = CellArray()
c.cell_set(1, 'Alice')
c.cell_set(2, 42)
print(c.cell_get(1))  # 'Alice'

# Struct with both access styles
s = Struct(name='Alice', age=30)
print(s.name, s['age'])

# Vector-argument sprintf
print(sprintf('%d\n', [1, 2, 3]))  # '1\n2\n3\n'

# MATLAB-style timing
t0 = tic()
# ... code ...
toc()  # "Elapsed time is X seconds."
```

## License

MIT. No runtime calls to external services; everything is pure Python.
