how to create vector 1 1 1 1 1 1 2 2 2 2 2 2?
0 件のコメント
回答 (3 件)
Hi lior,
Try using the repelem function. This function repeats each element of an input vector a specific number of times. Here's how you can achieve the desired vector:
% Define the elements to repeat
elements = [1 2];
% Define the number of repetitions for each element
repetitions = [6 6];
% Create the vector with repeated elements
result_vector = repelem(elements, repetitions);
% Display the result
disp(result_vector);
So, first define the elements [1 2] that you want to repeat and the number of repetitions [6 6] for each element, use repelem function to generate the vector result_vector with the desired pattern. Finally, use disp to display the result. Please see attached results.
Hope, this answers your question.
0 件のコメント
参考
カテゴリ
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!