MATLAB save command and transpose command

  • Context: MATLAB 
  • Thread starter Thread starter Saladsamurai
  • Start date Start date
  • Tags Tags
    Matlab Transpose
Click For Summary

Discussion Overview

The discussion revolves around the use of the MATLAB save command in conjunction with the transpose operation for saving row vectors as columns in text files. Participants explore the challenges of passing transposed variables to the save function without creating new variables.

Discussion Character

  • Technical explanation, Debate/contested, Conceptual clarification

Main Points Raised

  • One participant expresses a desire to save row vectors as columns in text files using the transpose operation but encounters issues with MATLAB interpreting the transpose syntax incorrectly.
  • Another participant clarifies that the save function requires variable names as strings, which complicates the use of transposed variables directly.
  • A participant questions the efficiency of creating new variables for each transposed vector, suggesting that it may be unnecessary since the transpose operation occurs in memory.
  • One participant suggests that a wrapper function could be created to streamline the saving process for transposed vectors, providing a sample function as an example.

Areas of Agreement / Disagreement

Participants generally agree on the limitations of the save function regarding variable names and the challenges of efficiently handling multiple transpositions, but no consensus is reached on the best approach to resolve these issues.

Contextual Notes

Participants mention the need for efficient handling of multiple row vectors and the implications of memory usage when transposing data. The discussion does not resolve the best method for saving transposed vectors without creating new variables.

Who May Find This Useful

Individuals working with MATLAB who need to save data in specific formats, particularly those dealing with vector transpositions and file output operations.

Saladsamurai
Messages
3,009
Reaction score
7
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:
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
 
Physics news on Phys.org
any takers on this one?
 
Saladsamurai said:
any takers on this one?

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.
 
FrogPad said:
Why is,

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

not efficient?

I mean, the transpose has to be done somewhere in memory.

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:).
 
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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 5 ·
Replies
5
Views
7K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
11K
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
15K
  • · Replies 3 ·
Replies
3
Views
5K