MATLAB compatibility helpers for Python code converted by matlabtopython.com
Project description
matlabtopython-compat
Runtime helpers for Python code converted from MATLAB by matlabtopython.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
pip install matlabtopython-compat
Optional .mat file I/O adds a scipy dependency:
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
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matlabtopython_compat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: matlabtopython_compat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16c409c6734fe6d4f190b26010e1272f73c788e0d3bd1204637cd489521d366
|
|
| MD5 |
06027b2acbf90f4eaf6965c888f5ece3
|
|
| BLAKE2b-256 |
abbd0100648fa5bdf154598c255e93d3cd01f21bcd60ea80ffee3d3ef65246b2
|