How do I change the matlab so that data is written in one column and several lines?

In matlab the standard is to record the data of a variable in a row and multiple columns, however I noticed that in this configuration the processing time is much higher. How do I change the matlab so that data is written in one column and several lines?

Réponses (2)

I do not know of a "standard to record the data of a variable in a row and multiple columns"; what application are you referring to?
If you want to convert from row vector 1xN to column vector Nx1, use the colon operator :
x = x(:);

6 commentaires

Hello Dear Thorsten,
thank you for your answer. Let me give an example.
Every time that matlab record some values it does:
columns
row 10 5 3 9 -1 13 4 0 16 20 ....
and not column row 10 row 5 row 3 row 9 row -1 row 13 row 4 row 0 row 16 row 20
with the latter, the calculations are faster than with the previous format.
I want to change the matlab configurations for always use the last format.
What exactly do you mean by "record some values"? What function are you using to get these values?
Thorsten,
I have a program with many functions and inside of them I have many for. There are for with 86400 iterations, which does a variable x, for instance, to have 1 row and 86400 columns and this makes that program slower than if this same variable x had 86400 rows and 1 column.
I trying discovery a method to change this matlab metodology of to store values in columns to store in rows, this will do my program faster.
BR. Jesse
It's not Matlab per se, but your program that uses this storage scheme. You have to change it in the program. Also, the program may be vectorized to get rid of the for loop. It would be helpful if you post this program.
Jesse Gomes
Jesse Gomes le 17 Sep 2015
Modifié(e) : Stephen23 le 17 Sep 2015
Dear Thorsten,
please find below the function. All variables contains only zeros and ones.
BR
Stephen23
Stephen23 le 17 Sep 2015
Modifié(e) : Stephen23 le 17 Sep 2015
@Jesse Gomes: I saved your function as a text file and uploaded it as an attachment. This is preferred to placing large amounts of code as text (it is easier to download the whole file, and most people will not bother to scroll through or read long code).
In future you can upload files yourself by using the paperclip button above the textbox. There are also buttons for formatting code and other useful stuff that make them worth a look.
Your code also used mixed leading tabs and spaces, so I replace them all with spaces. It pays to be consistent within one file.

Connectez-vous pour commenter.

In any operation upon pure vectors (arrays in which all except one dimension are length 1), the speed of processing rows or columns is exactly the same. MATLAB stores all vectors as consecutive entries in memory.
When you start working with arrays that are 2 or more dimensions, some operations may be faster along the first dimension, processing "down columns". The difference becomes more noticeable when the arrays extend to megabytes; for anything much smaller it usually is not worth the effort to change the code.

Modifié(e) :

le 17 Sep 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by