📄 renumber.m
字号:
function [newsubs, newsz] = renumber(subs, sz, range)%RENUMBER indices for sptensor subsref%% [NEWSUBS,NEWSZ] = RENUMBER(SUBS,SZ,RANGE) takes a set of% original subscripts SUBS with entries from a tensor of size% SZ. All the entries in SUBS are assumed to be within the% specified RANGE. These subscripts are then renumbered so that,% in dimension i, the numbers range from 1:numel(RANGE(i)).%% See also SPTENSOR/SUBSREFnewsz = sz;newsubs = subs;for i = 1 : size(sz,2) if ~(ischar(range{i}) && range{i} == ':') if (isempty(subs)) newsz(i) = numel(range{i}); else [newsubs(:,i), newsz(i)] = ... renumberdim(subs(:,i), sz(i), range{i}); end endend %------------------------------------------------------function [newidx, newsz] = renumberdim(idx, sz, range)%RENUMBERDIM helper function for RENUMBER% See also SPTENSOR/PRIVATE/RENUMBER% Determine the size of the new rangenewsz = numel(range);% Create a map from the old range to the new rangemap = zeros(1, sz);for i = 1 : newsz map(range(i)) = i;end% Do the mappingnewidx = map(idx);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -