Selecting values from an array when the array changes?

I want to select pairs from an array, with the array changing size, there is no specification of the size that the array can be. The numbers in the array are not ordered.
For X = [ 1 2 3 4 5 6]
I would get LINK = [1 2] [2 3] [3 4] [4 5] [5 6]
For X = [1 2 3]
I would get LINK =[1 2] [2 3]
In my code LINK would be a temporary variable and would loop through each value it can be.
Thanks

댓글 수: 2

What are the criteria for pairs? Why is [1 3] not a pair?
They have to be next to each other and in the same order as in the array. I actually just figured it out though. I think it should work, and it worked with my small example. Given L as the array:
[c,d] = size(L);
numlink = d - 1;
for templ = 1:numlink;
templink = [L(templ),L(templ+1)];
for j = 1:l;
end

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

답변 (1개)

Guillaume
Guillaume 2016년 3월 30일
How about:
link = [x(1:end-1); x(2:end)]'
and iterate over the rows. Or if you really want to have individual arrays in a cell array:
link = num2cell([x(1:end-1); x(2:end)]', 2)

카테고리

도움말 센터 및 File Exchange에서 Get Started with Phased Array System Toolbox에 대해 자세히 알아보기

태그

질문:

2016년 3월 30일

댓글:

2016년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by