Effacer les filtres
Effacer les filtres

Find slope across columns of cell

3 vues (au cours des 30 derniers jours)
Carver Nabb
Carver Nabb le 4 Jan 2019
Commenté : Bob Thompson le 7 Jan 2019
I have a 220x4 cell (a) consisting of numerical data and would like to find the (linear) slope across the four values in row one, then the four values in row two, and so on, so that I would end up with 220 different slopes that I could then save. Thanks in advance!

Réponse acceptée

Bob Thompson
Bob Thompson le 4 Jan 2019
How are you organizing the data into ordered pairs? I'm assuming that by 'numerical data' you mean you have cells that contain individual doubles.
data = cell2mat(a);
for i = 1:size(a,1)
slope(i) = polyfit(x_vals,data(i,:),1);
end
  6 commentaires
Carver Nabb
Carver Nabb le 7 Jan 2019
This worked great, Bob, thank you. However, now that I have NaN values, the polyfit function returns only NaN for P and S when the row contains a NaN value. Is there a way to ignore the NaNs?
Bob Thompson
Bob Thompson le 7 Jan 2019
for i = 1:size(a,1);
pairs = [];
pairs(:,1) = counter;
pairs(:,2) = data(i,:);
pairs = pairs(~isnan(pairs(:,2),:);
slope(i) = polyfit(pairs(:,1),pairs(:,2),1);
end
This might not quite do it, the logic indexing to remove NaNs might be slightly off, but it should get you going at least.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by