loop error with "unique" and "interp1"
Show older comments
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.)
Accepted Answer
More Answers (1)
Walter Roberson
on 30 Apr 2023
0 votes
cgft(nsub, :) is all the same value so the second output of unique is only a single entry
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!