How can my argument be used to create a matlab file?

Demetri Pananos

I am writing a function that converts a 2d python array into a matlab file. Here is my code so far...

def save_array(arr,fname):

import scipy.io 
import numpy



out_dict={}

out_dict[fname]=arr

scipy.io.savemat(fname.mat,out_dict)`

I want fname to be a string, but I am not sure how I can get the savemat part to work.

mattexx
import scipy.io
import numpy as np

def save_array(arr, arrname, fname):
    """
    Save an array to a .mat file
    Inputs:
      arr: ndarray to save
      arrname: name to save the array as (string)
      fname: .mat filename (string)
    """
    out_dict={arrname: arr}
    scipy.io.savemat(fname,out_dict)

save_array(np.array([1,2,3]), 'arr', 'test.mat')

Might be worth doing a python tutorial or two. This is very basic stuff!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python: how to check if optional argument can be used?

From Dev

How to create/generate/export a file from my webpack 2 config to be used inside of my React code?

From Dev

How to pass a ".mat" file as an argument in Octave/Matlab

From Dev

How to pass a ".mat" file as an argument in Octave/Matlab

From Dev

How can I create my own spelling file for vim?

From Dev

How can I create my class in different file?

From Dev

Creating a file that can be only used by my program. How do I differ it from other programs' files?

From Dev

How can I prevent my file from being used by another process?

From Dev

Matlab: how to receive a function (like exp) as an argument in my routine?

From Dev

Matlab: how to receive a function (like exp) as an argument in my routine?

From Dev

How to create external js file for a popup procedure that can be used in any page?

From Dev

How can I determine which version of Excel was used to create a .xls file?

From Dev

How to create a .sks file to used in spriteKit app

From Dev

How can I convert data which form is matlab file to LMDB as my caffe input?

From Dev

How to create a database that can be used by many users?

From Dev

How to access the contents of a file that is used as an argument when running a bash script?

From Dev

My app can create a file, but cannot read it

From Dev

How to create multiple functions in single matlab file

From Dev

How to create a graph in matlab from a .mat file?

From Dev

How can I define variables within an HTML file, which are used in an external JS file, when importing the JS code into my HTML?

From Dev

How can I create systematic matrices in MATLAB?

From Dev

MATLAB: How can I create autocorrelated data?

From Dev

How can I tell if my <List> is being used by my program?

From Dev

How can I used ReadAllLines with gzipped file

From Dev

Can a TypeConverter be used for constructor argument

From Dev

can this this strlen argument be used for validation?

From Dev

How do I retrieve the names of functions used in an .m file in MATLAB?

From Dev

How can i write bits to a file in matlab

From Dev

how can transform a matrix matlab into file .txt?

Related Related

  1. 1

    Python: how to check if optional argument can be used?

  2. 2

    How to create/generate/export a file from my webpack 2 config to be used inside of my React code?

  3. 3

    How to pass a ".mat" file as an argument in Octave/Matlab

  4. 4

    How to pass a ".mat" file as an argument in Octave/Matlab

  5. 5

    How can I create my own spelling file for vim?

  6. 6

    How can I create my class in different file?

  7. 7

    Creating a file that can be only used by my program. How do I differ it from other programs' files?

  8. 8

    How can I prevent my file from being used by another process?

  9. 9

    Matlab: how to receive a function (like exp) as an argument in my routine?

  10. 10

    Matlab: how to receive a function (like exp) as an argument in my routine?

  11. 11

    How to create external js file for a popup procedure that can be used in any page?

  12. 12

    How can I determine which version of Excel was used to create a .xls file?

  13. 13

    How to create a .sks file to used in spriteKit app

  14. 14

    How can I convert data which form is matlab file to LMDB as my caffe input?

  15. 15

    How to create a database that can be used by many users?

  16. 16

    How to access the contents of a file that is used as an argument when running a bash script?

  17. 17

    My app can create a file, but cannot read it

  18. 18

    How to create multiple functions in single matlab file

  19. 19

    How to create a graph in matlab from a .mat file?

  20. 20

    How can I define variables within an HTML file, which are used in an external JS file, when importing the JS code into my HTML?

  21. 21

    How can I create systematic matrices in MATLAB?

  22. 22

    MATLAB: How can I create autocorrelated data?

  23. 23

    How can I tell if my <List> is being used by my program?

  24. 24

    How can I used ReadAllLines with gzipped file

  25. 25

    Can a TypeConverter be used for constructor argument

  26. 26

    can this this strlen argument be used for validation?

  27. 27

    How do I retrieve the names of functions used in an .m file in MATLAB?

  28. 28

    How can i write bits to a file in matlab

  29. 29

    how can transform a matrix matlab into file .txt?

HotTag

Archive