# I want to concatenate two coloumns of table.

조회 수: 11 (최근 30일)
Aakriti Srivastava 2022년 6월 9일
댓글: Aakriti Srivastava 2022년 6월 10일
Two coloumns of my table are as follows:
Freqa Freqb
950 1500
2000 2070
3000 3070
4000 4070
And I want to provide this as an input to my function of different module which need input freq as
freq
950
1500
2000
2070
3000
3070
4000
4070
And using this command c= [freqa(:,1); freqb(:,2)]. MATLAB shows me this error: All tables being vertically concatenated must have the same variable names. I cant chnage the variable of my excel sheet so how to perform this concatenation operation please let me know.

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

### 채택된 답변

Jon 2022년 6월 9일
I am assuming you have a single MATLAB table, let's call it T, with two columns, one called freqa and another freqb.
In this case, you can do what you want using:
freq = [T.freqa;T.freqb]
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Aakriti Srivastava 2022년 6월 10일
Thanks it worked. I was wrong with my notation to columns.

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

### 추가 답변 (1개)

Voss 2022년 6월 10일
편집: Voss 2022년 6월 10일
Let's say you have a table t with variables freqa and freqb.
freqa = [950; 2000; 3000; 4000];
freqb = [1500; 2070; 3070; 4070];
t = table(freqa,freqb);
Then freq given below is a column vector of all elements of freqa and freqb in the required order:
% one way:
freq = reshape([t.freqa t.freqb].',[],1)
freq = 8×1
950 1500 2000 2070 3000 3070 4000 4070
% another way:
freq = reshape(t{:,{'freqa' 'freqb'}}.',[],1)
freq = 8×1
950 1500 2000 2070 3000 3070 4000 4070
Or, let's say you have two tables freqa and freqb
freqa = table([950; 2000; 3000; 4000],[1500; 2070; 3070; 4070]);
freqb = table([950; 2000; 3000; 4000],[1500; 2070; 3070; 4070]);
(so that I can reproduce the error you got using the code you showed)
try
c= [freqa(:,1); freqb(:,2)]
catch ME
disp(ME.message);
end
All tables being vertically concatenated must have the same variable names.
If that's the situation, then you can construct freq (or c if you want to call it that) like this:
freq = reshape([freqa{:,1} freqb{:,2}].',[],1)
freq = 8×1
950 1500 2000 2070 3000 3070 4000 4070
In either case, you can make the result freq into a table by
freq = table(freq)
freq = 8×1 table
freq ____ 950 1500 2000 2070 3000 3070 4000 4070
if that's what the input of the function needs to be.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
Aakriti Srivastava 2022년 6월 10일
the spreadsheet file attached hope this make more clarity.
Aakriti Srivastava 2022년 6월 10일
Thanks Voss, after your discription to solution I understand my mistake.

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

### 카테고리

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

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by