:cell matrix: transfering the second element of a row to the second element of the next row
Show older comments
Dear all,
I have the following problem I have a cell matrix A where the first 2 columns are
[1x28 char] [ NaN]
[ NaN] [ NaN]
'MAR' 'EECE'
'PRODEGORY' 'TOOSTE'
[ NaN] [ NaN]
[1x26 char] 'CGATE'
' CONSISIZE' 'COLG 75ML'
' POPUIZE' [1x30 char]
[1x26 char] 'SEDYNE'
' CONSIZE' [1x21 char]
'MAR' 'HYPEKETS'
'PRODTEGORY' 'TOPASTE'
My goal is the following:
IF the first element of a row is ‘MAR’ then transfer the second element of the same row to the second element of the next row.
For instance, rows 3 and 4 should become
'MAR' 'EECE'
'PRODEGORY' ' EECE TOOSTE'
Similarly for the last 2 rows that should be transformed to
'MAR' 'HYPEKETS'
'PRODTEGORY' ' HYPEKETS TOPASTE'
the other rows must remain untransformed
thanks
5 Comments
Yash
on 9 Jul 2012
try them in a loop , do u want this all in a single variable
Please, Sabbas, do not write "did not work", but explain what happens. Do you get an error message, if so, which one? Or do the results differ from your expectations?
It would be helpful if you post the input data in valid Matlab syntax, such that we can copy&paste them and test our suggestions. It would be friendly to make it as easy as possible to help you.
Sabbas
on 9 Jul 2012
Jan
on 9 Jul 2012
ANY(ISMEMBER()) is much less efficient than ANY(STRCMP()).
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!