Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB save command and transpose command

  1. Apr 30, 2009 #1
    I have a bunch of row vectors saved as objects r1 r2 r3. I would like to send each set of data (row) to a text file, but I want it to save as a column. This means that I want to save the transpose of the data, i.e., r1' r2'...

    Unfortunately, when I try to use
    Code (Text):
    save r1.txt r1' -ascii
    MATLAB thinks that the quote ' is an unbalanced string.

    I know that an "easy fix" would be to create new objects like R1=r1';

    but I don't really think that is efficient. How can I get around this?

    thanks
    Casey
     
  2. jcsd
  3. May 5, 2009 #2
    any takers on this one?
     
  4. May 5, 2009 #3
    As far as I know, the matlab function SAVE expects the following arguments:

    save(<string (filename)>, <string (variable name 1)>, ... <string (variable name N)>, <string (options)>)

    You are not passing the function actual variables, just the names. That's why you can't pass r1', because that is not a string.


    Why is,

    r1 = r1';
    save('rrrrrs.txt', 'r1', '-ascii');

    not efficient?

    I mean, the transpose has to be done somewhere in memory.
     
  5. May 5, 2009 #4
    Because if I have ten r values, I have to create 10 new R=r' values.

    I suppose I could write a for loop that does it for me, but for only 10 entries, that seemed a little tedious (possibly just laziness :smile:).
     
  6. May 5, 2009 #5
    lol, yeah.

    You could probably write a wrapper around the save function, to do what you want.


    function tSave(V)

    vt = V';

    save([num2str(V) '.txt'], 'vt', '-ascii');

    end

    then just call this little function instead
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MATLAB save command and transpose command
Loading...