How to print information based on ids in another column?

조회 수: 1 (최근 30일)
andrew
andrew 2014년 5월 14일
댓글: Star Strider 2014년 5월 14일
I have a list of ids in one column and color in the 2nd column. how do i print information based on the id. if you scan through the entire id and if apple is a match it should print out red in the column next to it. The final output should be this
  • apple red
  • apple red
  • banana yellow
  • apple red
  • pear green
  • banana yellow
  • pear green

답변 (1개)

Star Strider
Star Strider 2014년 5월 14일
Not really certain what you want, but this should get you started:
C = [{'banana'} {'yellow'};
{'apple'} {'red'};
{'pear'} {'green'}];
Q = C{strcmp(C, 'apple'), 2}
  댓글 수: 2
andrew
andrew 2014년 5월 14일
So i would like to search through column 1 which is 1x821 matrix and use a strcmp to compare part of a string to the name in column 1. If there is a match I would like to print the information that is relevant to matched information in column 1
Star Strider
Star Strider 2014년 5월 14일
You have a 1-row by 821-column vector by your description.
The impression I got from your question is that you have a matrix and are getting the information on some of the elements in the rows that matched the information in the first column.

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

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by