How can I make a linspaced matrix from two arrays

1 view (last 30 days)
a = [2,5,4]';
b = [4,7,6]';
In this case, I want to know a simple operation to get the matrix below from those two matrixes a and b.
c = [2,3,4; 5,6,7; 4,5,6];
I expected matlab to move like this;
c = [a:b];
But it didn't work.

Accepted Answer

KSSV
KSSV on 10 Nov 2017
Edited: KSSV on 10 Nov 2017
Or run a loop:
a = [2,5,4]';
b = [4,7,6]';
A = cell(length(a),1) ;
for i = 1:length(a)
A{i} = a(i):b(i) ;
end
A = cell2mat(A)
  1 Comment
Yusuke Kadowaki
Yusuke Kadowaki on 10 Nov 2017
Edited: Yusuke Kadowaki on 10 Nov 2017
Thank you for your comments. The function you put is what I wanted. FYI: I checked the link and in the comment someone says this function is faster than the one you shared.

Sign in to comment.

More Answers (0)

Categories

Find more on 行列および配列 in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!