필터 지우기
필터 지우기

Find slope across columns of cell

조회 수: 3 (최근 30일)
Carver Nabb
Carver Nabb 2019년 1월 4일
댓글: Bob Thompson 2019년 1월 7일
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!

채택된 답변

Bob Thompson
Bob Thompson 2019년 1월 4일
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
Carver Nabb
Carver Nabb 2019년 1월 7일
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 2019년 1월 7일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by