create cell array containing neighbour element

조회 수: 1 (최근 30일)
bbah
bbah 2019년 11월 21일
댓글: bbah 2019년 11월 21일
Hi,
i have a matrix gnbh(ngex2). My first column gives me the index in -x direction and my second in +x direction.
I start with first_element = find(gnbh(:,1)==0)
now i want to add to a matrix my second_element = gnbh(first_element,2) for each first element in a row. my third element will be
third_element = gnbh(second_element,2) and fourth_element = gnbh(third_element,2) and so on.
input = gnbh(ngaps,2)
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 0
1 18
2 19
3 20
4 21
5 -1
6 0
7 22
8 23
10 24
11 25
12 26
13 27
16 29
17 30
18 31
19 32
20 33
21 34
-1 35
22 37
23 38
24 40
25 41
26 43
27 -1
28 44
0 45
29 46
30 47
0 48
31 0
32 49
0 50
33 -1
35 51
36 52
37 0
38 54
39 55
41 -1
42 -1
44 0
45 59
0 60
47 61
48 62
0 63
-1 0
0 65
52 66
53 67
54 0
55 69
attention: if the second column is 0 i will continue with the next cell array.
my output will be a cell where every cell matrix shows me my 1st element my 2nd and so on until the last element ) in a row
e.g. output = cell = number of first elements x 1
and every cell contains a row matrix starting with my 1st element e.g 1x1 = [1 10 18 25 32 41 0], 1x2 = [2 11 19 26 33 42 52 63 0]
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 21일
Sorry, the question is still unclear to me? Could you please add small example with expected output?
bbah
bbah 2019년 11월 21일
my question is how do i jump to the next element to get the next element
my input is the matrix above
for i = 1:length(first_elements_withngb)
j = first_elements_withngb(i)
next_element = gnbh(j,2)
element_row{i,1} = [j next_element]
end
here now i got my cell with my first and second element
e.g
[1,10]
[2,11]
as you can see i started with my first element of "my_first_elements_withngb" (here called "j") and got the second element and added it to my cell array.
Now i need to set my next element as my "j" and add the next element to my cell array. i hope it was clear this time

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by