MATLABのtableを使用する際に、各列の配列名を取得するためには、どうすればよいのでしょうか。
↓A,Bをtableから抽出したいです。
   A    B
---------------------------------------
1| 43 44

2 comentarios

Kojiro Saito
Kojiro Saito el 20 de Feb. de 2024
AとBの左右に全角のスペースが入っていますが、実際のデータまたはファイルもそのようになっていますか?
晃平
晃平 el 20 de Feb. de 2024
コメントありがとうございます。
A,Bは列名、1は行名、43,44はテーブル内の1行目データです。
テーブルデータの列名A,Bの値を取得したいです。 

Iniciar sesión para comentar.

 Respuesta aceptada

Shunichi Kusano
Shunichi Kusano el 20 de Feb. de 2024

0 votos

次のようにアクセスできます。
t = table([43],[44],'VariableNames',{'A','B'})
t = 1x2 table
A B __ __ 43 44
t.Properties.VariableNames
ans = 1x2 cell array
{'A'} {'B'}

5 comentarios

晃平
晃平 el 21 de Feb. de 2024
ありがとうございます。
追加で質問なのですが、t.Properties.VariableNamesで取得した、
AとBを変数として使いたい場合はどのようにすればよろしいでしょうか。
A=数値 をワークスペースに登録
Shunichi Kusano
Shunichi Kusano el 21 de Feb. de 2024
それぞれ別々の変数として使いたい、ということでしょうか。下記のような感じでいかがでしょうか。
t = table([43],[44],'VariableNames',{'A','B'});
variableNames = t.Properties.VariableNames;
A = variableNames{1}
A = 'A'
B = variableNames{2}
B = 'B'
Takashi Ueno
Takashi Ueno el 21 de Feb. de 2024
文字列から変数を作成されたいのであれば、assigninあるいはevalでしょうか。
t = table([43],[44],'VariableNames',{'A','B'});
variableNames = t.Properties.VariableNames;
assignin('base',variableNames{1},1);
A
A = 1
value2=2;
eval([variableNames{2},'=value2;'])
B
B = 2
Dyuman Joshi
Dyuman Joshi el 21 de Feb. de 2024
"AとBを変数として使いたい場合はどのようにすればよろしいでしょうか"
Once again, why do you want to do that?
晃平
晃平 el 26 de Feb. de 2024
解決できました。
ありがとうございます。
str{変数名}=Value{値};
str{1,2}=Value{1,1};

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 20 de Feb. de 2024

Comentada:

el 26 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!