Table setup to rearrange where titles are

28 visualizzazioni (ultimi 30 giorni)
Micah
Micah circa 8 ore fa
Commentato: the cyclist circa 6 ore fa
I am struggling to get my table to look the way I want it to, I want the titles to be on the left instead of on top of my table.
x=0:1:10;
y=[10,12,15,19,23,25,27,32,34,36,41];
table(x,y)
ans = 1x2 table
x y _____________________________________________________________ ______________________________________________________________ 0 1 2 3 4 5 6 7 8 9 10 10 12 15 19 23 25 27 32 34 36 41
I wish to get it so the inputs of x are on top of the inputs of y
  1 Commento
the cyclist
the cyclist circa 6 ore fa
Before suggesting a way of displaying your data, we may need to understand how your data are structured -- and what they represent.
The norm (not just in MATLAB) is that columns list variables, and rows list observations. Each entry in the table is the value of that variable, for that observation.
It is unclear to me, from what you have posted, the structure of your data. Which is these do you have?
  • 11 observations of two variables (x and y), where each value is scalar
  • 1 observation of two variables (x and y), where each value is a length-11 vector
  • 2 observations of 11 variables (unnamed), where each value is a scalar (and these observations are named "x" and "y")
  • 2 observations of a single variable (unnamed), where each value is a length-11 vector (and these observations are name "x" and "y")
  • something else?
Note that @Animesh's solution implicitly assumes the third option (or possibly the first option, but just showing the table transposed from the norm).
It is very difficult (at least for me) to suggest a solution without understanding the data structure.

Accedi per commentare.

Risposte (1)

Animesh
Animesh circa 7 ore fa
Hi @Micah,
To create a table with titles on the left instead of on top, you can use MATLAB's table functionality and transpose the data.
You can try something like this:
T = table(x', y', 'VariableNames', {'x', 'y'});
% Transpose the table to have titles on the left
T_transposed = array2table([T.x, T.y]', 'RowNames', {'x', 'y'});
disp(T_transposed);
Here, "x" and "y" are first made into a table with the "table" function, and then it's transposed using "array2table" to switch the rows and columns, with "RowNames" used to label the rows.
You can refer the following MathWorks documentation for more information on "array2table":

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by