Cut a matrix after a certain value

12 visualizaciones (últimos 30 días)
luca
luca el 26 de Sept. de 2019
Respondida: Bjorn Gustavsson el 26 de Sept. de 2019
Given the following matrix
Acum=[116.200000000000 237.300000000000 329.300000000000 391.200000000000 561 619.900000000000 719.900000000000 785.900000000000 902.900000000000 967.900000000000 1022.90000000000;
174.200000000000 342.600000000000 429.100000000000 513.600000000000 781.800000000000 845.600000000000 945.600000000000 1011.60000000000 1128.60000000000 1193.60000000000 1248.60000000000;
232.300000000000 432.200000000000 523.000000000000 584.900000000000 912.100000000000 971.000000000000 1071 1137 1254 1319 1374;
290.400000000000 521.800000000000 613.800000000000 675.700000000000 1042.40000000000 1101.30000000000 1201.30000000000 1267.30000000000 1384.30000000000 1449.30000000000 1504.30000000000;
348.500000000000 611.400000000000 704.600000000000 766.500000000000 1172.70000000000 1231.60000000000 1331.60000000000 1397.60000000000 1514.60000000000 1579.60000000000 1634.60000000000;
406.600000000000 701 795.400000000000 857.300000000000 1303.00000000000 1361.90000000000 1461.90000000000 1527.90000000000 1644.90000000000 1709.90000000000 1764.90000000000;
464.600000000000 806.300000000000 892.800000000000 977.300000000000 1523.80000000000 1587.60000000000 1687.60000000000 1753.60000000000 1870.60000000000 1935.60000000000 1990.60000000000;
522.600000000000 911.600000000000 998.100000000000 1082.60000000000 1744.60000000000 1808.40000000000 1908.40000000000 1974.40000000000 2091.40000000000 2156.40000000000 2211.40000000000;
580.700000000000 1001.20000000000 1092 1153.90000000000 1874.90000000000 1933.80000000000 2033.80000000000 2099.80000000000 2216.80000000000 2281.80000000000 2336.80000000000;
638.800000000000 1090.80000000000 1182.80000000000 1244.70000000000 2005.20000000000 2064.10000000000 2164.10000000000 2230.10000000000 2347.10000000000 2412.10000000000 2467.10000000000;
696.900000000000 1180.40000000000 1273.60000000000 1335.50000000000 2135.50000000000 2194.40000000000 2294.40000000000 2360.40000000000 2477.40000000000 2542.40000000000 2597.40000000000;
754.900000000000 1285.70000000000 1372.20000000000 1456.70000000000 2356.30000000000 2420.10000000000 2520.10000000000 2586.10000000000 2703.10000000000 2768.10000000000 2823.10000000000;
812.900000000000 1391.00000000000 1477.50000000000 1562.00000000000 2577.10000000000 2640.90000000000 2740.90000000000 2806.90000000000 2923.90000000000 2988.90000000000 3043.90000000000;
870.900000000000 1496.30000000000 1582.80000000000 1667.30000000000 2797.90000000000 2861.70000000000 2961.70000000000 3027.70000000000 3144.70000000000 3209.70000000000 3264.70000000000;
929.000000000000 1585.90000000000 1676.70000000000 1738.60000000000 2928.20000000000 2987.10000000000 3087.10000000000 3153.10000000000 3270.10000000000 3335.10000000000 3390.10000000000]
With the code
rowNum = find(any(Acum > 2500,2),1,'first'); % 1440*60= 86400 secondi. è il tempo disponibile nella giornata
CUM=Acum(1:rowNum-1,:);
I want to cut the matrix as soon as I meet a value > 2500.
Till here it's all right. But if the matrix contain all the values < 2500. "rowNum" doesn't exist and I cannot find CUM, while instead if rownum doesn't exist is simply CUM=Acum.
For example, considering
Acum1=[116.200000000000 237.300000000000 329.300000000000 391.200000000000 561 619.900000000000 719.900000000000 785.900000000000 902.900000000000 967.900000000000 1022.90000000000;
174.200000000000 342.600000000000 429.100000000000 513.600000000000 781.800000000000 845.600000000000 945.600000000000 1011.60000000000 1128.60000000000 1193.60000000000 1248.60000000000;
232.300000000000 432.200000000000 523.000000000000 584.900000000000 912.100000000000 971.000000000000 1071 1137 1254 1319 1374;
290.400000000000 521.800000000000 613.800000000000 675.700000000000 1042.40000000000 1101.30000000000 1201.30000000000 1267.30000000000 1384.30000000000 1449.30000000000 1504.30000000000;
348.500000000000 611.400000000000 704.600000000000 766.500000000000 1172.70000000000 1231.60000000000 1331.60000000000 1397.60000000000 1514.60000000000 1579.60000000000 1634.60000000000;
406.600000000000 701 795.400000000000 857.300000000000 1303.00000000000 1361.90000000000 1461.90000000000 1527.90000000000 1644.90000000000 1709.90000000000 1764.90000000000;
464.600000000000 806.300000000000 892.800000000000 977.300000000000 1523.80000000000 1587.60000000000 1687.60000000000 1753.60000000000 1870.60000000000 1935.60000000000 1990.60000000000;
522.600000000000 911.600000000000 998.100000000000 1082.60000000000 1744.60000000000 1808.40000000000 1908.40000000000 1974.40000000000 2091.40000000000 2156.40000000000 2211.40000000000]
the code
rowNum = find(any(Acum1 > 2500,2),1,'first'); % 1440*60= 86400 secondi. è il tempo disponibile nella giornata
CUM=Acum1(1:rowNum-1,:);
give me an empty matrix CUM.
May someone help me to construct a code that coinsider both the options?
thanks

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 26 de Sept. de 2019
Try:
rowNum = find(any(Acum1 > 2500,2),1,'first'); % 1440*60= 86400 secondi. è il tempo disponibile nella giornata
if isempty(rowNum)
CUM = Acum;
else
CUM = Acum1(1:rowNum-1,:);
end
HTH

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by