renumber.m
来自「张量分析工具」· M 代码 · 共 40 行
M
40 行
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 + =
减小字号Ctrl + -
显示快捷键?