loop error with "unique" and "interp1"
Afficher commentaires plus anciens
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.)
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 30 Avr 2023
0 votes
cgft(nsub, :) is all the same value so the second output of unique is only a single entry
1 commentaire
Phillip
le 30 Avr 2023
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
