필터 지우기
필터 지우기

making new objocts out of the content of a cell vector

조회 수: 1 (최근 30일)
Birgit
Birgit 2012년 10월 18일
Hello!
I am everything else than an expert in Matlab, but I hope that my explanation still makes sense to you. My problem is the following:
I have a vector that looks like this:
B = {'USA' 'GER' 'JAP'...}'; (it is actually 110 country codes
now I want to assign each country code a number like: USA = 1; GER = 2; JAP = 3; ... (keeping the same order as in the vector)
Is there a quick way of doing this?? I would be very glad if I don't have to write 110 country codes by hand!
Thaaaaank you very much!!

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 10월 18일
It sounds like you might want to use a containers.Map object.
doc containers.Map
And an example:
cm = containers.Map({'USA';'GER';'JAP'},[1;2;3]);
And a sanity check, is 'USA' number 1?
cm('USA')
You betcha!

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 18일
B = {'USA' 'GER' 'JAP'}
B=[B;num2cell(1:numel(B))]

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by