how to match data with 3 differnt datasets with different data sizes

조회 수: 3 (최근 30일)
andrew
andrew 2013년 9월 23일
I currently have 2 sets of data and I am trying to find a match based off of it's name. For example in data1 it contains apple, banana, orange, pear,etc and data 2 contains apple-1, apple-2, apple-3, banana-1, banana-2, banana-3, orange, pear-1, pear-2, etc. data3 contains red, yellow, and orange. Ultimately, I would like to write a script to match for example apple with apple-1, apple-2, apple-3 etc and with the color red, yellow, orange etc and print out the corresponding data:
Col 1 Col 2 Col 3
apple apple-1 red
apple apple-2 red
apple apple-3 red
banana banana-1 yellow
banana banana-2 yellow
banana banana-3 yellow
orange orange orange
pear pear-1 green
pear pear-2 green

답변 (1개)

Matt J
Matt J 2013년 9월 23일
편집: Matt J 2013년 9월 23일
One way,
Col2={'apple-1';'apple-2';'banana-5';'pear-3'}
S.apple='red';
S.banana='yellow';
S.pear='green';
Col1 = regexprep(Col2,'[\W\d]','');
Col3 = cellfun(@(c) S.(c), Col1,'uni',0);
C=[Col1,Col2,Col3]

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by