Repeat some elements in a vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali Tawfik
am 4 Mai 2020
Bearbeitet: Ameer Hamza
am 4 Mai 2020
clear all;
u={'High';'M';'LOW'}
y=repelem(u(1:3),2)
% would like the output y=[high;M;LOW;high;M;Low]
I am trying to use repelem but I repeat the element it self n number of times not as I mentioned before
I would like to repeat al the u 2 times with the same sequence
Thanks,
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 4 Mai 2020
Bearbeitet: Ameer Hamza
am 4 Mai 2020
repmat() is the correct function to use here
u={'High';'M';'LOW'}
y=repmat(u(1:3),2,1)
Result
y =
6×1 cell array
{'High'}
{'M' }
{'LOW' }
{'High'}
{'M' }
{'LOW' }
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!