フィルターのクリア

Generating a number with specific number of times.

2 ビュー (過去 30 日間)
RDG
RDG 2013 年 3 月 26 日
Is there any better way to perform these in matlab? eg:
i) Generating a number with specific number of times.
a=[1 2 3 4 5]; %The data
b=cell(10,1);
for i=1:3 %Each data will appear a specific number of times
b{i}=a(1);
end
for j=1:1
b{j+i}=a(2);
end
for k=1:2
b{k+j+i}=a(3);
end
for l=1:1
b{l+k+j+i}=a(4);
end
for m=1:3
b{m+l+k+j+i}=a(5);
end
c=b; %Store the processed data into a variable.

採用された回答

Image Analyst
Image Analyst 2013 年 3 月 26 日
No need to make it complicated with a cell array when a normal numerical array will work just fine:
a=[1 2 3 4 5];
counts = [3, 1, 2, 1, 3]
b = [];
for k = 1 : length(a)
b = [b, a(k) * ones(1, counts(k))];
end
b
Results in command window
b =
1 1 1 2 3 3 4 5 5 5

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by