How to create the following cell array with the following pattern quickly

2 views (last 30 days)
Hi,
I would like to create the following cell array quickly without explicitly stating the elements as I am doing now:
marker = {'s','o','d','p','x','+','*','>', ...
'o','d','p','x','+','*','>','s', ...
'd','p','x','+','*','>','s','o', ...
'p','x','+','*','>','s','o','d', ...
'x','+','*','>','s','o','d','p', ...
'+','*','>','s','o','d','p','x', ...
'*','>','s','o','d','p','x','+', ...
'>','s','o','d','p','x','+','*'}
As you can see there is a pattern here, there are 8 unique marker types and each consecutive group of 8 markers is based on the first 8 markers...I am new to matlab and would like to know if there is any intrinsic function that I could use or some sort of looping algorithm to create this cell array. I ask because I may need a larger cell array down the road and I think this is inefficient.
[EDITED, Jan, format improved]
  3 Comments
shah72206
shah72206 on 30 Aug 2012
Thanks Jan...the way you formatted it is how I had formatted it on my code but couldn't get it to format it that way here

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 30 Aug 2012
m = {'s' 'o' 'd' 'p' 'x' '+' '*' '>'};
idx = hankel(1:numel(m),[numel(m) 1:numel(m)-1]);
marker = m(idx(:)');
  2 Comments
shah72206
shah72206 on 30 Aug 2012
Excellent. Many thanks to Andrei and Oleg. I am going with the hankel solution since I do not understand the second one. I had not recognized that particular pattern in my cell array and even if I had, I would not have known about this hankel matrix (engineer!).
This was my first post on an online forum and I feel like I should've started using forums much earlier!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!