필터 지우기
필터 지우기

how to write a function?

조회 수: 1 (최근 30일)
Sky Scrapper
Sky Scrapper 2019년 1월 24일
댓글: Sky Scrapper 2019년 1월 28일
I have a matrix:
A= [0 80 -100 0 1 0 1 0 1 0 1 ;...
0 0 0 0 1 0 1 1 0 1 0 ;...
-100 0 0 0 1 1 0 0 1 0 1 ;...
-100 100 0 0 1 1 0 1 0 1 0 ;...
100 0 -100 1 0 0 1 0 1 0 1 ;...
100 0 0 1 0 0 1 1 0 1 0 ;...
0 0 0 1 0 1 0 0 1 0 1 ;...
0 100 0 1 0 1 0 1 0 1 0 ]
Now i need to make a function if i type:
0 1 0 1 0 1 0 1
then it will show the corresponding total row. so, it'll show:
0 80 -100 0 1 0 1 0 1 0 1
But i don't know how to do. Can anyone please help me?
  댓글 수: 4
Star Strider
Star Strider 2019년 1월 24일
The result you want is simply the first row of ‘A’.
Is the argument vector you want to enter in your function some sort of code that the function has to interpret?
Sky Scrapper
Sky Scrapper 2019년 1월 24일
편집: Sky Scrapper 2019년 1월 24일
I will enter the value (of column 4 to 11), it will search the whole matrix and find out in which row that given data is found and will show.

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

채택된 답변

Guillaume
Guillaume 2019년 1월 24일
tofind = [0, 1, 1, 0, 0, 1, 0, 1];
found = A(ismember(A(:, 4:11), tofind, 'rows'), :)
will return all the rows of A whose columns 4 to 11 match tofind.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by