How do I limit the repmat?
3 次查看(过去 30 天)
显示 更早的评论
I am trying to create a function to code or decode a message and was suggested that i use repmat and mod. I understand how the mod works but the repmat is confussing me. lets say my message is:
MATLAB
and the key is:
[2,4,6,3]
How would i get the key to become:
[2,4,6,3,2,4]
to change each of the letters in matlab? I realize that I need to use double to convert the text to numbers and char to convert the changed numbers back to text.
Any help would be Appreciated.
0 个评论
采纳的回答
Sean de Wolski
2013-3-21
One way:
str = 'MATLAB'
key = [2,4,6,3];
%Replicate it to be slightly bigger and lop off the end.
keysz = repmat(key,1,ceil(numel(str)./numel(key)));
keysz = keysz(1:numel(str));
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2013-3-21
编辑:Azzi Abdelmalek
2013-3-21
x=[2,4,6,3]
y=repmat(x,1,2) % Duplicate horizontally twice
y=y(1:6)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!