Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

selecting multiple strinfs of variables

Asked by Stef on 14 May 2012

Dear all,

I have produced the following output

county interst rate

England b1

England b1

England b1

England b1

England b2

England b2

England b2

England b3

England b3

England b4

England b4

The above table says that for England we have different types of interest rate. I would like to select the values of interest rates that correspond to both bi and b2.

If I use the command

strcmp(mdata1(:,2),'b1')

 i select only b1. But I want to select both b1 and b2 Any suggestions? 

thanks in advance,

stef

0 Comments

Stef

Products

No products are associated with this question.

2 Answers

Answer by Titus Edelhofer on 14 May 2012
Accepted answer

Hi Stef,

I guess you are looking for ismember:

ismember(mdata(:,2), {'b1' 'b2'})

Titus

1 Comment

Stef on 14 May 2012

Hi Titus,

It worked!. thank you so much. I would like to ask you something relevant to the previous question. Apart from the above columsn I have also another column that takes numerical values but has the following structure

[10]
[10]
[10]
[10]
[10]
[10]
[10]
[10]
[10]
[10]
[10]
[8]
[8]
[8]
[8]
[ 7]
[ 7]
[ 7]
[ 0]
[ 0]
Again, I want to select b1 and b2 from the column
"interest rate ínterest" AND the number 7 and 0 from the above column so as to find the corresponding values of interest rates.

I was thinking something like

ismember(mdata(:,2), {'b1' 'b2'}) & something else" "
but i do not know what this "something else" is. your help is greatly appreciated

Titus Edelhofer
Answer by Stef on 14 May 2012

Hi Titus,

It worked!. thank you so much. I would like to ask you something relevant to the previous question. Apart from the above columsn I have also another column that takes numerical values but has the following structure

[10]

[10]

[10]

[10]

[10]

[10]

[10]

[10]

[10]

[10]

[10]

[8]

[8]

[8]

[8]

[ 7]

[ 7]

[ 7]

[ 0]

[ 0]

Again, I want to select b1 and b2 from the column "interest rate ínterest" AND the number 7 and 0 from the above column so as to find the corresponding values of interest rates.

I was thinking something like

ismember(mdata(:,2), {'b1' 'b2'}) & something else" " but i do not know what this "something else" is. your help is greatly appreciated

Comment on this Answer

2 Comments

Titus Edelhofer on 14 May 2012

The values you have seem to be a cell array. Convert it to a double array:

doubleArray = cell2mat(cellArray);

Then you can use it lile

ismember(mdadata(:,2), {'b1' 'b2'}) & (doubleArray==0 | doubleArray==7)

Stef on 14 May 2012

Thank you so much for one more time. you were correct!

Stef

Contact us