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

creating more efficient loops

Asked by tzaloupas on 4 Feb 2013

Dear all,

I have the following lists

``` A={ 'fi','ffggi'...};
AROT={ 'rttgfi','kil'...};
SEWQW={ 'dfet','vfse'...};```

which are replaced by the following lists , respectively

``` A1={ 'der','gtyhu'...};
AROT1={ 'sdderr','bnhtf'...};
SEWQW1={ 'gbnn','klop'...};```

within a cell matrix (named 'raw')

So I have

``` for k=1:numel(A)
raw(find(strcmp(raw,A{k})))={A1{k}};
end```
``` for k=1:numel(AROT)
raw(find(strcmp(raw,AROT{k})))={AROT1{k}};
end```
``` for k=1:numel(SEWQW)
raw(find(strcmp(raw,SEWQW{k})))={SEWQW1{k}};
end```

As you can see I repeat the same process for each list Yet, I have 100 such lists that should be replaced by other 100 lists

Is there any way to construct more efficient loops instead of doing this separately for each list?

thanks

Jan Simon on 4 Feb 2013

Note: You can omit the find in your code.

tzaloupas on 5 Feb 2013
```is there a way of constructing efficent loops?  I am struggling to find a way but cant. could you please help me?
```

thanks

tzaloupas on 5 Feb 2013

I am still struggling how to do it. could pelase some help me?

thanks

Products

No products are associated with this question.

Answer by Doug Hull on 4 Feb 2013

Your naming convention is what is making this hard for you. I would use a cell array of cells, so you can loop through all the cells doing the same operation.

1 Comment

tzaloupas on 5 Feb 2013

can you be more specific?

tbanks