how do I extract top half of the data into a separate matrix and the bottom half into its own matrix?
7 views (last 30 days)
Show older comments
ThermodynamicProperties =
1.0e+03 *
0.2000 0.0002 2.6129 2.8161
0.2500 0.0002 2.7047 2.9356
0.3000 0.0002 2.7897 3.0463
0.3500 0.0002 2.8727 3.1542
0.4000 0.0003 2.9555 3.2613
0.5000 0.0003 3.1234 3.4770
NaN NaN NaN NaN
NaN NaN NaN NaN
0.2000 0.0001 2.6027 2.8030
0.2500 0.0002 2.6989 2.9279
0.3000 0.0002 2.7857 3.0409
0.3500 0.0002 2.8697 3.1501
0.4000 0.0002 2.9531 3.2581
0.5000 0.0003 3.1218 3.4748
0 Comments
Accepted Answer
KSSV
on 10 Nov 2020
A = 1.0e+03 *[ 0.2000 0.0002 2.6129 2.8161
0.2500 0.0002 2.7047 2.9356
0.3000 0.0002 2.7897 3.0463
0.3500 0.0002 2.8727 3.1542
0.4000 0.0003 2.9555 3.2613
0.5000 0.0003 3.1234 3.4770
NaN NaN NaN NaN
NaN NaN NaN NaN
0.2000 0.0001 2.6027 2.8030
0.2500 0.0002 2.6989 2.9279
0.3000 0.0002 2.7857 3.0409
0.3500 0.0002 2.8697 3.1501
0.4000 0.0002 2.9531 3.2581
0.5000 0.0003 3.1218 3.4748] ;
idx = find(isnan(A(:,1))) ;
B = A(1:idx(1)-1,:) ;
A(1:idx(1)+length(idx),:) = [] ;
0 Comments
More Answers (1)
Ameer Hamza
on 10 Nov 2020
Here is one way
A = [
0.2000 0.0002 2.6129 2.8161
0.2500 0.0002 2.7047 2.9356
0.3000 0.0002 2.7897 3.0463
0.3500 0.0002 2.8727 3.1542
0.4000 0.0003 2.9555 3.2613
0.5000 0.0003 3.1234 3.4770
NaN NaN NaN NaN
NaN NaN NaN NaN
0.2000 0.0001 2.6027 2.8030
0.2500 0.0002 2.6989 2.9279
0.3000 0.0002 2.7857 3.0409
0.3500 0.0002 2.8697 3.1501
0.4000 0.0002 2.9531 3.2581
0.5000 0.0003 3.1218 3.4748]*1e3;
idx = ~all(isnan(A),2);
idx2 = cumsum([1; diff(idx)]>0).*idx;
A_split = splitapply(@(x) {x}, A(idx,:), idx2(idx));
Result
>> A_split{1}
ans =
1.0e+03 *
0.2000 0.0002 2.6129 2.8161
0.2500 0.0002 2.7047 2.9356
0.3000 0.0002 2.7897 3.0463
0.3500 0.0002 2.8727 3.1542
0.4000 0.0003 2.9555 3.2613
0.5000 0.0003 3.1234 3.4770
>> A_split{2}
ans =
1.0e+03 *
0.2000 0.0001 2.6027 2.8030
0.2500 0.0002 2.6989 2.9279
0.3000 0.0002 2.7857 3.0409
0.3500 0.0002 2.8697 3.1501
0.4000 0.0002 2.9531 3.2581
0.5000 0.0003 3.1218 3.4748
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!