Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How can I extract points (sum of values) from variable size groups of lines (separated from NaN values) in the same column ?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, here is my problem.
I have this two columns.
A=[1; 2; 5; NaN; 4; 6; 8; 65; 6; NaN; NaN; NaN; 33; 5; 7]
B=[5; 8; 5; NaN; 4; 7; 8; 66; 8; NaN; NaN; NaN; 32; 1; 7]
I want a new matrix with two coluns with the sum of each group (in each column) that is separated by NaN values sequences to develop a scatter graph.
Answer:
C=[8 18;89 93;45 40]
Thanks!
0 Kommentare
Antworten (1)
Tommy
am 28 Mai 2020
Potentially over-complicated but should work:
cA = cumsum([A, B],'omitnan');
idx = [isnan(A(2:end)); 1] & ~isnan(A);
C = diff([0, 0; cA(idx,:)]);
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!