Last active
June 6, 2018 17:01
-
-
Save dominem/570300f7db3751cc1807b3e62610b9d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
x_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
y_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
colors = ['black', 'white', 'red'] | |
types = ['-', '*', '+'] | |
for index, value in enumerate(values): | |
plot(x_values[index], y_values[index], colors[index], types[index]) | |
# You can do it better by using just a single array | |
args = [((1, 2, 3), (1, 2, 3), 'black', '-'), ((2, 3, 4), (2, 3, 4), 'white', '*'), ((5, 6, 7), (5, 6, 7), 'red', '+')] | |
for index, arg in enumerate(args): | |
plot(*args[index]) # The asterisk - * unpacks these argument, so that this is equivalent to the prior loop | |
# Actually, in python you can do it better: | |
x_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
y_values = [(1, 2, 3), (2, 3, 4), (5, 6, 7)] | |
colors = ('black', 'white', 'red') | |
types = ('-', '*', '+') | |
args = zip(x_values, y_values, colors, types) | |
for arg_tuple in args: | |
plot(*arg_tuple) | |
# In Matlab, there may be a similar solution, I think, but I'm not sure. | |
# A similar solution to unpack and pass a tuple of arguments to a function call. | |
# I think this a solution is there: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html | |
# There is a paragraph named "Function Call Arguments". | |
# Once again, I don't know Matlab, so I'm not sure if this is similar solution to the same problem. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment