How to transform a vector that have "*" to indicate that a number is repeated
조회 수: 1 (최근 30일)
이전 댓글 표시
hello,
I have a relative simple question... I have a vector A=[3*2 1 5*10] and I would like that this vector will be transformed in a column vector B=[2 2 2 1 10 10 10 10 10]'... How to do it in an efficient manner? By the way, the first number in A is the frequency of the following number is repeated...
Regards,
댓글 수: 2
Fangjun Jiang
2021년 12월 6일
see repmat(), repelem(), as long as you can provide A in a recognizable format
Walter Roberson
2021년 12월 6일
is it a text vector? Because if you entered that into matlab you would not be able to distinguish between needing 3 3 or needing 2 2 2 or needing 1 1 1 1 1 1
채택된 답변
Mathieu NOE
2021년 12월 6일
hello
my suggestion :
A='3*2 1 5*10';
As = split(A);
out_all = [];
for ci = 1:numel(As)
B = split(As{ci},'*');
BB = str2double(B);
if numel(B)>1 % then we have a multiplier
out = repmat(BB(2),1,BB(1));
else
out = BB;
end
out_all = [out_all out];
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Analog Devices ADALM1000 Support from Data Acquisition Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!