generate a sequence from matrix
조회 수: 3 (최근 30일)
이전 댓글 표시
given matrix:
new =[
35 28 21 14 7 0
30 23 16 9 2 5
25 18 11 4 3 10
20 13 6 1 8 15
15 8 1 6 13 20
10 3 4 11 18 25
5 2 9 16 23 30
0 7 14 21 28 35]
i need to evaluate from 8th row,1st column.
i need to traverse from 0,2,3,1,1,3,2,0 (least element in each row)
and assign values 1 0 1 1 1 0 1 ( 1 when traversing diagonally and 0 when traversing sideways or upward but not backward or downward)
댓글 수: 0
채택된 답변
dpb
2019년 7월 29일
Interesting...kinda' cute solution...altho note that the suggested answer is wrong; the minimum for row 7 is the 3 in column 2, not 4 in colum 3
[~,j]=min(flipud(new),[],2);
ix=diff(j)~=0;
Above returns
ix =
7×1 logical array
1
0
1
1
1
0
1
>>
댓글 수: 5
dpb
2019년 7월 30일
Well, you've just broken any chance for a one-liner I can see... :)
You'll have to do some preprocessing to eliminate the duplicated minima where they exist before calling the above algorithm or have to go back afterwards and check for duplicates and clean up the result if founc.
Or, just loop from the git-go and don't try to be fancy and find each next location one-at-a-time accounting for the duplicates as you go.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!