Azzera filtri
Azzera filtri

The values from the for loop won't store on the array

2 visualizzazioni (ultimi 30 giorni)
When running this piece of code, pendiente(i) will display the values, but when I exit the loop the array shows up as empty. What am I doing wrong?
for i = 1 : length(epsilon_l_embuticion)-2
pendiente(i) = (sigma_mpa_embuticion(i+1)-sigma_mpa_embuticion(i))/(epsilon_l_embuticion(i+1)-epsilon_l_embuticion(i));
pendiente(i)
end
pendiente
  5 Commenti
Torsten
Torsten il 26 Ott 2023
Except for some Inf values in "pendiente", everything works out fine (see above).
Dyuman Joshi
Dyuman Joshi il 26 Ott 2023
Modificato: Dyuman Joshi il 26 Ott 2023
I have ran your code here, just to show that the result is not empty, but instead of importdata(), use readmatrix or readtable or readcell, as they are more robust functions.
Also, consider Preallocation for the variable pendiente
There is a big disparity in the (absolute) values of output, from the order of 10^2 to 10^13, thus smaler values might "appear" to be zero or "empty", but they are not.
Use the shortg format to have a better idea of the values -
B = importdata("Acero_embuticion.txt")
B = struct with fields:
data: [652×3 double] textdata: {'Sigma (MPa)' 'epsilon l' 'epsilon t'} colheaders: {'Sigma (MPa)' 'epsilon l' 'epsilon t'}
sigma_mpa_embuticion = B.data(:, 1);
epsilon_l_embuticion = B.data(:, 2);
epsilon_t_embuticion = B.data(:, 3);
for i = 1 : length(epsilon_l_embuticion)-2
pendiente(i) = (sigma_mpa_embuticion(i+1)-sigma_mpa_embuticion(i))/(epsilon_l_embuticion(i+1)-epsilon_l_embuticion(i));
%pendiente(i)
end
format shortg
disp(pendiente.')
170 -2521.7 688.33 -13433 20189 Inf -23894 -4.5024e+06 32221 2.0249e+07 40178 2.3557e+07 5.8627e+09 4.7884e+13 51916 55571 1.6129e+07 61308 -64592 67217 70963 -74570 77721 2.2017e+07 84006 86623 -91363 47262 8.2746e+06 1.0124e+05 5.6245e+07 1.0696e+05 1.0853e+05 3.0821e+07 1.1479e+05 6.3918e+07 1.2106e+05 1.2367e+05 1.2523e+05 1.2754e+05 1.4007e+08 Inf 1.3567e+05 1.3984e+05 1.4193e+05 1.4311e+05 1.4711e+05 5.625e+07 76707 -1.5754e+05 80339 1.3821e+07 82443 4.6023e+07 1.7115e+05 1.7323e+05 1.7636e+05 1.7526e+05 1.7844e+05 1.8052e+05 1.8044e+05 1.8471e+05 1.8681e+05 1.8891e+05 1.887e+05 1.9304e+05 1.9623e+05 1.97e+05 2.0249e+05 2.0346e+05 2.0458e+05 2.0529e+05 2.0868e+05 1.0488e+05 2.1054e+05 2.1285e+05 5.8241e+07 2.1703e+05 1.0853e+05 2.1781e+05 1.0958e+05 4.7321e+07 1.1166e+05 2.2538e+05 1.1322e+05 2.5348e+07 1.1479e+05 2.3058e+05 2.3233e+05 2.3686e+05 1.1897e+05 2.375e+05 1.2054e+05 2.4157e+05 2.4416e+05 2.4529e+05 1.2366e+05 2.4469e+05 2.4633e+05 2.4366e+05 2.4633e+05 1.226e+05 2.4167e+05 1.2106e+05 2.395e+05 2.3694e+05 1.1738e+05 2.3125e+05 2.3155e+05 2.2963e+05 2.2711e+05 1.1379e+05 2.2403e+05 2.2321e+05 1.1012e+05 2.1881e+05 1.0953e+05 2.1673e+05 2.1703e+05 2.151e+05 2.1486e+05 1.0703e+05 1.047e+05 2.0968e+05 2.0775e+05 2.0768e+05 1.0227e+05 2.0106e+05 2.003e+05 98097 1.9399e+05 1.8885e+05 94423 1.8447e+05 91334 1.8164e+05 89163 1.7424e+05 85574 1.6589e+05 1.6494e+05 81399 79310 1.5548e+05 1.5342e+05 74136 71965 70018 68876 1.3271e+05 43041 1.2425e+05 39709 1.164e+05 37321 53264 50342 31934 45333 43886 27935 26880 25328 35732 22215 21382 31307 19938 19385 18272 17716 16496 15717 11605 14995 14441 13773 10227 19492 9559.2 12108 8640.1 11338 11274 8181.7 10885 10830 7722.5 9788.7 7138.1 9386.8 9552.4 7179.8 9346.3 7054.6 9330.2 6887.6 6595.4 8572.1 6511.9 8738 6553.7 6511.9 8184.9 8052.9 5844 5551.8 7576.6 7664.1 5677.1 5677.1 5550.9 7411.5 5550.9 5175.3 6803.1 5179.6 6850.8 5304.9 6992.2 5096.1 5058 4757.9 6000 4591 4632.7 6250 3645.5 8649.1 4302.4 5271.9 3759.4 4519.5 4208.3 4126.7 4131.9 5309.7 4599.6 4036.6 4692.7 3883.1 4922.6 3798 3849.4 3923.2 5500 4210.3 3234.6 3474.8 4123 4646 2573.5 3853.5 3842.9 4861.9 3647.4 3239.5 3694 3503.3 3425.3 2813.7 2371 2459.4 2671.1 2921.5 3282.6 2663.3 3414.5 3245.9 4162 2882.2 3015.8 3089.8 3395.1 2107 3761.1 2963.3 2711.7 2337.2 3212.8 2262.1 2629.4 2569 2754.6 3130.2 3520.5 2497.2 2997.1 2839.2 3484.5 1804.8 2188.4 2488.9 1836.4 2149.6 2054.8 2478.6 2412.6 2630.5 2973.4 2836 2029.3 2796.3 3122 3020.9 2147.4 2521.4 2087.7 1869.7 2942.8 2084.2 2253.8 2489.6 3074.4 2388 2664.1 2764.5 2128.5 1952.8 1423.4 2323 1940.7 2149.6 2149.4 2516.6 2740.7 2355.1 3220.4 3305.6 2775.5 3104.2 1984.8 2041.1 2388.9 1794.7 1752.9 2122.3 2764.5 2495.8 2463.5 3042 2295.5 2316.4 2104.1 1435.7 1419 1617.5 1794.7 1924.2 1623 2045.1 2545.2 2381 2774.7 2017.8 2764.5 2330.4 2573.9 2191.2 1756 1930 1911.4 1768.6 2128.5 2450 1888.4 2197 2611.1 2003.3 1596.8 1744.5 1651.5 1903.9 1544.2 1679.8 1957.8 2383.2 2108.6 2426.3 2226.4 2090.9 2030.9 2003.3 1975.9 2101.4 1430.5 2053.5 2302.9 1878.1 1777.3 2192.6 2003.3 2015.8 1575.5 1620.6 1544.2 1618.3 1729.4 1757.6 1771.6 2433.6 2090.9 2015.2 2005 2170.3 2197.3 2833.3 1582.9 1909.1 1753.7 1935.8 1586 2278.8 1846.7 2287.9 1851.1 2015.8 1532.2 1419 1733.1 1788.4 1443.6 1754.4 2097.2 2378.3 1648.6 1909.1 2164.6 1669.4 2091.5 1485.7 1926.7 2086.8 2181.9 1711.2 2074.7 2139 1443.8 1560.5 1944.4 1419 1236.9 1478.8 1602.2 2164.3 1888.9 1669.4 2043.6 1909.1 2055.6 1711.2 1878.1 2043.6 1430.2 1900.6 1831.7 1572.1 1920.2 2511.2 1871.9 1759.7 1818.7 1586 1305.8 1111.1 1345 1515.6 1377.3 1602.2 2219.8 1865.9 1747.8 2277.8 1694 2831.8 1652 1252.1 1539.7 1653.5 1653.2 1836.4 2073.4 1982.4 1503.8 1455.9 1420.2 1943.4 956.31 1333.3 1398.2 1880.5 1511.8 2167.3 1902.9 1752.9 2000 1912.8 1753.7 1252.1 1510.5 1606.1 1235.8 2444.4 2002.4 1785.7 1818.7 1333.9 1000.2 1077.9 1369.4 1770.6 2002.4 1876.5 1711.2 2060.6 1452.4 1235.8 1722.2 1623.2 1269.2 1692.1 2021.9 1711.2 1731.6 1565.1 1659.8 1817.9 876.46 1106.1 1126.9 1197 1194.1 2754.6 1697.5 1636.4 1831.1 1942.3 1933.7 1273.1 1545.5 1252.1 1289.4 1682.3 2029.3 1481.6 1991.2 1544.2 1712.7 1123 927.69 1213.1 903.01 1293.9 1651.5 1629.1 1989 1503.8 2014.7 1803.6 1818.2 1200.8 1848.2 1042.5 1293.8 1948.7 1558 1398.7 1368.2 1286.9 1065.2 1567.7 1238.7 1515.6 1590.9 1515.7 1377.3 1757.6 1562.5 1580.2 1420.2 1500 1060.7 1406.1 1916.7 1203.2 1638.5 1377.3 1712.7 1318.6 709.52 1035.7 1043.4 1167.1 1715.5 1627.7 1662.7 1800.6 1627.7 1832.5 1546.1 958.33 1511.9 1335.6 1288.3 1848.8 1595.9 1861.1 1500 1470.6 1729.9 1144.4 1000 1196.2 1373.6 1144.4 1789.3 1405 1250 1694.4 1416.7 1583.3 1302.5 1245.8 1595.2 1033.4 1291.7 1978 1545.5 1345.2 1344.5 1322.3 1238.1 1000 920.5 1255.9 1277.8 1244.4 1783.3 1409.1 1375 1700 1197.8 1373.6 1500 1129.7 1425.2 1050.4 1561.5 1554.6 1473

Accedi per commentare.

Risposte (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 26 Ott 2023
You can display/write out the calculated data, and store or write to an external files as well. See how it can be done:
A = readmatrix("Fundicion_gris.txt");
B = readmatrix("Acero_embuticion.txt");
sigma_mpa_embuticion = B(:, 1);
epsilon_l_embuticion = B(:, 2);
epsilon_t_embuticion = B(:, 3);
for i = 1 : length(epsilon_l_embuticion)-2
pendiente(i) = (sigma_mpa_embuticion(i+1)-sigma_mpa_embuticion(i))/(epsilon_l_embuticion(i+1)-epsilon_l_embuticion(i));
end
% The calculated data is stored/written into an external file called: Out_pendiente.txt
writematrix(transpose(pendiente), 'Out_pendiente.txt')
fprintf('ALL calculated data = pendiente : \n');
ALL calculated data = pendiente :
fprintf('%3.5f \n', transpose(pendiente))
169.99991 -2521.65826 688.33104 -13432.98908 20188.81386 Inf -23893.86479 -4502368.42105 32220.52282 20249080.88235 40178.13827 23556967.72542 5862662102.22770 47883870967750.37500 51916.18207 55570.95390 16129032.25806 61308.04294 -64591.91047 67216.72352 70963.43296 -74569.80574 77720.64260 22016818.18182 84005.67707 86622.58732 -91362.79617 47261.75873 8274647.88732 101235.59860 56245454.54544 106962.76507 108528.68497 30821100.91743 114793.78861 63918181.81812 121055.26799 123672.61070 125229.58758 127538.49217 140071428.57112 Inf 135665.38654 139839.70613 141926.86592 143106.02290 147111.85309 56249999.99997 76707.29671 -157536.54848 80339.43875 13821126.76056 82442.81182 46022727.27274 171147.10302 173234.26282 176356.65387 175261.32404 178443.81366 180517.52922 180438.02887 184705.29304 186809.15011 188911.15564 188702.72064 193038.39733 196225.78490 196997.34572 202488.30995 203455.75960 204575.81830 205291.97080 208681.13523 104883.95392 210537.67010 212854.75793 58240909.09085 217028.38063 108532.30923 217806.17325 109575.88913 47321428.57142 111663.04892 225375.62604 113224.24445 25348148.14816 114793.78861 230584.30718 232326.58480 236861.43573 118968.10820 237504.14869 120537.65236 241572.66092 244156.92821 245290.58116 123660.04341 244691.43995 246325.98530 243662.90644 246325.98530 122595.99332 241669.43246 121055.26799 239499.00464 236940.54776 117381.86676 231254.14731 231552.58765 229625.91850 227106.83477 113791.95191 224029.20677 223205.34224 110118.55068 218812.20969 109534.14593 216727.51411 217028.38063 215096.86039 214858.09683 107029.55418 104695.53675 209682.80467 207748.83100 207679.46578 102270.82985 201061.71201 200298.70561 98096.51027 193989.98331 188848.32393 94423.10903 184472.46184 91334.11254 181636.06010 89163.46635 174244.93860 85573.55151 165892.50166 164941.56928 81399.23193 79309.77269 155477.62191 153422.37062 74135.91585 71965.26966 70018.25120 68876.27317 132714.00133 43041.20849 124248.49699 39708.98589 116399.46560 37320.89304 53264.31792 50342.29421 31933.79984 45333.11070 43885.84702 27935.13273 26879.92891 25327.70495 35732.17566 22214.81728 21381.76164 31307.39689 19937.79851 19384.58120 18271.68722 17716.31678 16496.33415 15716.98323 11604.60845 14995.00167 14441.23528 13773.18672 10227.08299 19492.36894 9559.19185 12108.42035 8640.12021 11338.49558 11274.01977 8181.66639 10885.26047 10829.72343 7722.49123 9788.74018 7138.08649 9386.80293 9552.37143 7179.82969 9346.31125 7054.60010 9330.22326 6887.62732 6595.42495 8572.06061 6511.93855 8737.97146 6553.68175 6511.93855 8184.93529 8052.87127 5844.04742 5551.84505 7576.59551 7664.11196 5677.07464 5677.07464 5550.91820 7411.50442 5550.91820 5175.29215 6803.09735 5179.61571 6850.82873 5304.92899 6992.23085 5096.07352 5058.04312 4757.92988 6000.00000 4590.98497 4632.72120 6250.00000 3645.48495 8649.09390 4302.42272 5271.92009 3759.39850 4519.50523 4208.33333 4126.71947 4131.88648 5309.73451 4599.61868 4036.62089 4692.71081 3883.08977 4922.56637 3797.99666 3849.35497 3923.20534 5500.00000 4210.27593 3234.55760 3474.82314 4122.97426 4646.01770 2573.52941 3853.47288 3842.94069 4861.87845 3647.35306 3239.54091 3693.99428 3503.33651 3425.30923 2813.67236 2371.04825 2459.35807 2671.11853 2921.53589 3282.58801 2663.33749 3414.51767 3245.94257 4162.04218 2882.20551 3015.80699 3089.77035 3395.06173 2107.02341 3761.06195 2963.27212 2711.70314 2337.22871 3212.75583 2262.14238 2629.38230 2568.98192 2754.59098 3130.21703 3520.45671 2497.22531 2997.14558 2839.24843 3484.51327 1804.81283 2188.41184 2488.93805 1836.39399 2149.56101 2054.79452 2478.55100 2412.64559 2630.48017 2973.35871 2836.03432 2029.27478 2796.32721 3122.02097 3020.93245 2147.35283 2521.40818 2087.68267 1869.67790 2942.80955 2084.20175 2253.75626 2489.62656 3074.35653 2388.00444 2664.12940 2764.53765 2128.54758 1952.77021 1423.44191 2323.00885 1940.73456 2149.56101 2149.41569 2516.61918 2740.70543 2355.14798 3220.43309 3305.55556 2775.45910 3104.21286 1984.84848 2041.09969 2388.88889 1794.65776 1752.92154 2122.34707 2764.53765 2495.84027 2463.46555 3042.03540 2295.49249 2316.36060 2104.14774 1435.70537 1419.03172 1617.50714 1794.65776 1924.24242 1622.97129 2045.07513 2545.19505 2380.95238 2774.69478 2017.77120 2764.53765 2330.42031 2573.87989 2191.15192 1755.97941 1930.01944 1911.40777 1768.62256 2128.54758 2450.04757 1888.36434 2196.96970 2611.11111 2003.33890 1596.80639 1744.53883 1651.51515 1903.85531 1544.24040 1679.78208 1957.78950 2383.22212 2108.61650 2426.26070 2226.38369 2090.90909 2030.91846 2003.33890 1975.87354 2101.40093 1430.47239 2053.48615 2302.94397 1878.13022 1777.28409 2192.56435 2003.33890 2015.76235 1575.45605 1620.59104 1544.24040 1618.25726 1729.36893 1757.57576 1771.57149 2433.62832 2090.90909 2015.15152 2005.01253 2170.28381 2197.34660 2833.33333 1582.89364 1909.09091 1753.65344 1935.84071 1585.97663 2278.77578 1846.70925 2287.94643 1851.08153 2015.76235 1532.16019 1419.03172 1733.14340 1788.42073 1443.64242 1754.38596 2097.23546 2378.31858 1648.58097 1909.09091 2164.60514 1669.44908 2091.54289 1485.69842 1926.73644 2086.81135 2181.87875 1711.18531 2074.68880 2138.95631 1443.80275 1560.54931 1944.44444 1419.03172 1236.91722 1478.76362 1602.16396 2164.26193 1888.88889 1669.44908 2043.59673 1909.09091 2055.55556 1711.18531 1878.13022 2043.59673 1430.15829 1900.63354 1831.66818 1572.06455 1920.16934 2511.16071 1871.88020 1759.70874 1818.73295 1585.97663 1305.79297 1111.11111 1345.04224 1515.61079 1377.29549 1602.16396 2219.75583 1865.89806 1747.81523 2277.77778 1693.97390 2831.76013 1652.01576 1252.08681 1539.74199 1653.51942 1653.18744 1836.39399 2073.40324 1982.44552 1503.75940 1455.90682 1420.21721 1943.36480 956.30812 1333.33333 1398.16361 1880.53097 1511.78301 2167.32343 1902.94957 1752.92154 2000.00000 1912.84098 1753.65344 1252.08681 1510.46622 1606.06061 1235.76784 2444.44444 2002.42718 1785.71429 1818.73295 1333.92619 1000.15154 1077.94362 1369.40548 1770.58111 2002.42718 1876.48456 1711.18531 2060.60606 1452.38095 1235.76784 1722.22222 1623.17961 1269.24677 1692.08770 2021.88392 1711.18531 1731.60173 1565.10851 1659.75104 1817.87859 876.46077 1106.08944 1126.87813 1196.96970 1194.11275 2754.59098 1697.48409 1636.36364 1831.11380 1942.33687 1933.70166 1273.11306 1545.45455 1252.08681 1289.44175 1682.32798 2029.27478 1481.63606 1991.15044 1544.24040 1712.65461 1122.97087 927.68792 1213.13035 903.01003 1293.87651 1651.51515 1629.07268 1988.95028 1503.75940 2014.65201 1803.57684 1818.18182 1200.80053 1848.15185 1042.53545 1293.82304 1948.70087 1558.03996 1398.74739 1368.15920 1286.93994 1065.20934 1567.69596 1238.68509 1515.61079 1590.90909 1515.65623 1377.29549 1757.57576 1562.50000 1580.17299 1420.21721 1500.00000 1060.73211 1406.10105 1916.66667 1203.20856 1638.50486 1377.29549 1712.65461 1318.58139 709.51586 1035.71429 1043.40568 1167.09893 1715.52298 1627.71285 1662.70784 1800.60020 1627.71285 1832.46073 1546.14653 958.33333 1511.90476 1335.55927 1288.26917 1848.76749 1595.89231 1861.11111 1500.00000 1470.58824 1729.85782 1144.44444 1000.00000 1196.17225 1373.62637 1144.44444 1789.29766 1404.95868 1250.00000 1694.44444 1416.66667 1583.33333 1302.52101 1245.84718 1595.23810 1033.43465 1291.66667 1978.02198 1545.45455 1345.23810 1344.53782 1322.31405 1238.09524 1000.00000 920.50209 1255.92417 1277.77778 1244.44444 1783.33333 1409.09091 1375.00000 1700.00000 1197.77159 1373.62637 1500.00000 1129.70711 1425.17815 1050.42017 1561.46179 1554.62185 1473.02905
% An alternative way of storing the data is to use save()
save('Out_pendiente2.mat', pendiente)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by