Making a nested vector function

6 ビュー (過去 30 日間)
Rob Mullins
Rob Mullins 2016 年 4 月 7 日
回答済み: Walter Roberson 2016 年 4 月 7 日
Hey all, I feel really dumb about asking this but I am trying to make a function that takes in any two vectors of equal lengths and putting them together as so: vec1 = [1,2,3,4]; vec2 = [5,6,7,8]; newvec = [[1,5];[2,6];[3,7],[4,8]];
This is what I have so far:
function y = doublevec(vec1,vec2)
if (length(vec1) == length(vec2)) == 1
for i = 1:length(vec1)
j(i) = [vec1(i)]
for l = 1:length(vec2)
p(l) = [vec2(l)]
end
y(i,l) = [j(i);p(l)]
end
elseif (length(vec1) == length(vec2)) == 0
warning('Vectors must be same length')
end

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 4 月 7 日
[vec1(:), vec2(:)]

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by