Make Variable Names in a table numbers

27 ビュー (過去 30 日間)
Abinand Rejimon
Abinand Rejimon 2022 年 6 月 22 日
コメント済み: Abinand Rejimon 2022 年 6 月 22 日
I have a table that needs to have the variable names (columns) as numbers. When I try to assign the variablenames to the table t, i get this error. It is an array of 800 numbers that each have to be assigned a column. How do I make this work? Is there a way I can use array2table and specify the first row of numbers as the header? That is what I am trying to do below but it is not working.
t = array2table(allDataT(2:26,:)) %converting allDataT from rows 2 to 26 to a talbe
t.Properties.VariableNames = (allData(1,:)) % Trying to specify that the first row of numbers should be the header
% ERROR: The VariableNames property is a cell array of character vectors.
% To assign multiple variable names, specify nonempty names in a string arrayor a cell array of character vectors.

採用された回答

Jan
Jan 2022 年 6 月 22 日
Header are strings, not numbers. You cannot use numbers to be a header.
allData = reshape(1:64, 8, 8)
allData = 8×8
1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64
t = array2table(allData);
t.Properties.VariableNames = string(allData(1,:))
t = 8×8 table
1 9 17 25 33 41 49 57 _ __ __ __ __ __ __ __ 1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64
Instead of 1,9, ... you have the headers "1", "9", ...
  1 件のコメント
Abinand Rejimon
Abinand Rejimon 2022 年 6 月 22 日
Thank you so much for this! It really helps!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by