Doing operations on a row or a column only in a matrix

I want to do an If-else statment on a column seperately and get the end result( I am allowed to use whatever techniques possible) just for reference the question was to find the students who Gots A's B's and C's....etc . The user would input a matrix containing the Id no. In the first column and the score in second column Thanks

답변 (1개)

Elias Gule
Elias Gule 2016년 5월 13일
Let's assume you have the matrix:
Data = [1 96;2 75;3 88;4 30;5 60;6 14;7 88];
with column ordering as specified in your question.
Let's look for all students who scored 60 or more.
predicate = Data(:,2)>=60; %%find entries in the second column that are >= 60
rData = Data(predicate,:); %%return only the rows where the predicate is true
The rData matrix contains both the student id's and scores.
ids = rData(:,1); %%Get student id's
scores = rData(:,2); %%Get the corresponding scores

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2016년 5월 12일

답변:

2016년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by