Python equivalent to Matlab

This is the place for queries that don't fit in any of the other categories.

Python equivalent to Matlab

Postby Peglam » Fri May 03, 2013 1:06 am

in Matlab I can find the max magnitude along with the associated frequency in one step

Matlab Code
Code: Select all

In python I tried this
Code: Select all
  mag, phase, omega = freqresp(sys, [0.1, 1., 10.])
db,f = max(mag)

But it gives me an error. I can type in
Code: Select all
to get the max magnitude but I would also like to have the numeric freq associated. Any Ideas on how I can do this?
Posts: 3
Joined: Wed Apr 24, 2013 8:45 pm

Re: Python equivalent to Matlab

Postby stranac » Fri May 03, 2013 11:03 am

Most of us are not matlab users.
You should explain what that code does.

freqresp() is not a python built-in.
You should let us know what libraries you're using.

Peglam wrote:but I would also like to have the numeric freq associated

Assume we have no idea what a variable is supposed to represent.
Where would this second thing you want come from(which of your variables)?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1501
Joined: Thu Feb 07, 2013 3:42 pm

Re: Python equivalent to Matlab

Postby tnknepp » Mon May 06, 2013 9:03 pm

I'm familiar with Matlab, and I do not believe what you want can be done quite as nicely in Python. What you can do:

Code: Select all
from collections import Counter

# If you have a list of data
a = [1,2,3,4,5,1]

MAX,iter = (max(a),Counter(a)[max(a)])
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
Posts: 153
Joined: Mon Mar 11, 2013 7:41 pm

Return to General Coding Help

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests