Creating a unique vector with a pattern
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Terrell
il 14 Mag 2014
Modificato: Image Analyst
il 14 Mag 2014
I need to create a vector of the form
[1,4,2,4,......2,4,2,4,1]
this would be easy to create for a small vector but it will be around 2000 elements long. I tried to do this using a loop and an even or odd if statement with separate statements for the first and last elements but couldn't get it to work. Any ideas are appreciated,
0 Commenti
Risposta accettata
Image Analyst
il 14 Mag 2014
Modificato: Image Analyst
il 14 Mag 2014
What's the pattern? I can't quite figure it out. I know every other one is 4, but what about the 1 and the 2? It's not just alternating because there are 2 2's in a row near the end. Is it 4,2 except the very first and very last are 1? Or are there 1's in the middle somewhere?
Anyway, you know the rule (whatever it is), so just use repmat
y = repmat(.......
Then use
y(2:2:end) = 4;
Or maybe try this:
y = ones(1,2000);
y(2:2:end-1) = 2;
y(3:2:end-1) = 4
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!