How can I make a vector that looks like this [2 1 2 1 1 4 1 1 6 1 1 8...1 100 1]?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am attempting to make a 151 element vector that starts out like [2 1 2 1 1 4...] so that between the 3n elements in the vector after the initial 3 values of 2, 1, 2 there are 2 ones followed by a term that is 2 more than the value of the 3rd element in the vector i.e (2 1 1 4 1 1 6 1 1 8 1 1 10 1 1... ) all the way to 1 1 100 1 as the last 4 elements in the vector.
cv4 = [2 1 2 ones(1,148)];
for i = 1:75
cv4(:,2*(i+1)) = 2;
end
cv4
This is the code i've used so far but it isn't anywhere near right.
cv4 = 1×152
This is the vector I have so far... [2 1 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2]
2 Commenti
John D'Errico
il 6 Nov 2023
Your question is too confusing. Is the vector of length 151? Or 152?
What are the fist elements? In two places, I have seen it start out as
2 1 1 4 1 1 6 1 1 8 1 1 10
Or maybe this
2 1 2 1 1 4 1 1 6 1 1 8
So what do you want to do? Can we answer a question that is not even consistent?
Risposte (2)
John D'Errico
il 6 Nov 2023
Modificato: John D'Errico
il 6 Nov 2023
If I had to guess, you might want to do this:
V = ones(1,151);
V(1) = 2;
V(3:3:end) = 2:2:100;
V
The last few elements of the vector are:
V(140:151)
But your question is far too confusing to know if that is what you want or not.
Vedere anche
Categorie
Scopri di più su Historical Contests 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!