Finding values of specific range from table row or column
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yaser arafat kazi
am 25 Jul. 2019
Kommentiert: yaser arafat kazi
am 28 Jul. 2019
Hi,
I'm having the Table whose first column is as A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502]
I want to select range as 12345 to NaN (shown in bold) , 457 to NaN and so on.
Please guide.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 26 Jul. 2019
Bearbeitet: Stephen23
am 26 Jul. 2019
>> A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502].'
A =
12345
NaN
NaN
NaN
NaN
457
NaN
NaN
NaN
785
NaN
NaN
NaN
NaN
NaN
NaN
74502
Method one: accumarray:
>> C = accumarray(cumsum(~isnan(A)),A,[],@(v){v});
>> C{:}
ans =
12345
NaN
NaN
NaN
NaN
ans =
457
NaN
NaN
NaN
ans =
785
NaN
NaN
NaN
NaN
NaN
NaN
ans =
74502
Method two: mat2cell:
>> X = diff(find([true;diff(isnan(A))<0;true]));
>> C = mat2cell(A,X,1);
>> C{:}
ans =
12345
NaN
NaN
NaN
NaN
ans =
457
NaN
NaN
NaN
ans =
785
NaN
NaN
NaN
NaN
NaN
NaN
ans =
74502
Weitere Antworten (1)
Shreya Shetty
am 26 Jul. 2019
Bearbeitet: madhan ravi
am 26 Jul. 2019
Go through this. It might help you
1 Kommentar
madhan ravi
am 26 Jul. 2019
Bearbeitet: madhan ravi
am 26 Jul. 2019
No, indices should be determined by the code and not by giving it manually.
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!