How to define the number of the column in which a variable corresponds

조회 수: 1 (최근 30일)
Ivan Mich
Ivan Mich 2023년 1월 23일
댓글: Image Analyst 2023년 1월 23일
I have a question about a code. I use the following command in order to read a file:
T=readtable('file.txt')
A=(T:,1);
B=(T:,2);
C=(T:,3);
which command should I use in order to define the number of the column in which a variable corresponds?
for example A coresponts to column 1 (so I want answer=1), B coresponts to column 1 (so I want answer=2), , etc.
Could you please help me?
  댓글 수: 3
Ivan Mich
Ivan Mich 2023년 1월 23일
I would like to export the number 1 (that represents the number of specific column i T table) of command
A=(T:,1)
the number 2 of command
B=(T:,2)
the number 3 of command
C=(T:,3) etc...
Could you please help me?
Image Analyst
Image Analyst 2023년 1월 23일
I did help you. Below in the official Answers section. Did you even see it?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2023년 1월 23일
As soon as you assign A, B, and C, you can also create a dictionary so that later in your code you can recall what column they came from
T = randi(9, 5, 3);
A = T(:, 1);
B = T(:, 2);
C = T(:, 3);
dict = dictionary(["A"; "B"; "C"], [1;2;3])
dict =
dictionary (stringdouble) with 3 entries: "A" ⟼ 1 "B" ⟼ 2 "C" ⟼ 3
% What column is A from
col = dict("A")
col = 1
% What column is B from
col = dict("B")
col = 2
% What column is C from
col = dict("C")
col = 3

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by