⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repeat2.m

📁 《精通matlab7》“mastering matlab 7”的代码。
💻 M
字号:
% repeat2.m
% repeated value creation and counting

%x = [3 2 0 5 6];  % data to repeat
%n = [2 0 3 1 2];  % repeat counts

nz = n==0;            % locations of zero elements
n(nz) = [];           % eliminate zero counts
x(nz) = [];           % eliminate corresponding data
y = zeros(1,sum(n));  % preallocate array

idx = 1;                     % pointer into y
for i=1:length(x)
   y(idx:idx+n(i)-1) = x(i); % poke data into y
   idx = idx+n(i);           % next storage location
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -