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
Okay so the first 8 markers are s,o,d,p,x,+,*,> The next 8 are o,d,p,x,+,*,>,s The next 8 are d,p,x,+,*,>,s,o and so on... do you see it now? I basically wanna use the 8 unique ones and loop through and concatenate the cell array with 8 markers on every loop and following that pattern.
The overall purpose is to create a 1 x n structure with 3 fields ... color, linetype and marker. color and linetype each had a repeating pattern of colors and linetypes so that was easy to concatenate using a loop. But the markers have this pattern which is not trivial (for me at least) to generate in a loop.
The final goal is to have a structure as follows: prop(1x1) = color = 'black' linetype = '-' marker = 's' prop(2x2) = color = 'red' linetype = ':' marker = 'o' etc etc...
You must have guessed the application of this. To apply these fields in a loop that generates a multiline plot with different properties for each line.
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
Oleg Komarov
Oleg Komarov on 30 Aug 2012
Edited: Oleg Komarov on 30 Aug 2012
Another solution based on the circulant matrix:
idx = fliplr(gallery('circul',numel(m):-1:1));
marker = m(idx(:)');
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)

Categories

Find more on Line Plots 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!