loop error with "unique" and "interp1"
显示 更早的评论
Dear Matlab-Experts,
trying to find the 50% threshold for a sigmoid shaped curve using interp1 for a set of subjects. Managed to do single subjects here:
load cgft
load cgsx
size(cgft)
size(cgsx)
nsub = 8;
[~, ind1] = unique(cgft); % ind = index of first occurrence of a repeated value
yc(nsub, :) = interp1(cgft(ind1), cgsx(ind1), .50, 'linear','extrap');
But my loop for all 53 subject fails:
% for all subjects:
load cgft
load cgsx
subjects = [1:53];
nbsubjects = length(subjects);
for nsubs = 1:nbsubjects
nsub = subjects(nsubs);
[~, ind1] = unique(cgft(nsub, :));
yc(nsub, :) = interp1(cgft(ind1(nsub, :)), cgsx(ind1(nsub, :)), .50, 'linear','extrap');
end
Would anyone know why the loop doesn't run please? (I'm a matlab dabbler...not a regular user...)
(Error using matlab.internal.math.interp1
Interpolation requires at least two sample points for each grid dimension.)
采纳的回答
更多回答(1 个)
Walter Roberson
2023-4-30
0 个投票
cgft(nsub, :) is all the same value so the second output of unique is only a single entry
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
