MATLAB Answers

how to write a function?

1 view (last 30 days)
Sky Scrapper
Sky Scrapper on 24 Jan 2019
Commented: Sky Scrapper on 28 Jan 2019
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 Comments
Sky Scrapper
Sky Scrapper on 24 Jan 2019
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.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 24 Jan 2019
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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by