フィルターのクリア

Making one column from two columns

3 ビュー (過去 30 日間)
Muhsin
Muhsin 2017 年 10 月 13 日
回答済み: Image Analyst 2017 年 10 月 13 日
Hello;
I would like to build a column ( C) that is created by two different columns ( A and B) in text file in a specific array. For example;
A B
10 15
20 25
30 35
40
C
10
15
20
25
30
35
40
How can I achieve this? Thank you.
Muhsin

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 10 月 13 日
B1 = [B;0];
out = reshape([A(:)';B1(:)'],[],1);
out = out(1:end-1);

その他の回答 (2 件)

KSSV
KSSV 2017 年 10 月 13 日
A = [10 20 30 40]' ;
B = [15 25 35]' ;
% C = [10 15 20 25 30 35 40]'
N = length(A)+length(B) ;
D = zeros(N,1) ;
D(1:2:end) = A ;
D(2:2:end) = B ;
Read about MATLAB matrix indexing.

Image Analyst
Image Analyst 2017 年 10 月 13 日
Without giving any rules for how this is to be generalized, I'm going to assume that A and B are as given: a 4 element column array, and a 3 element column array. So in that case, to get C from a 4 element A and a 3 element B, you'd simply do
C = [A(1); B(1); A(2); B(2); A(3); B(3); A(4)]
If that doesn't work then you must say how A and B might be different than the example you gave. Otherwise, this one-liner is about as simple as you can get.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by