The values from the for loop won't store on the array
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2023-10-26
Except for some Inf values in "pendiente", everything works out fine (see above).
Dyuman Joshi
2023-10-26
编辑:Dyuman Joshi
2023-10-26
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.
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.
B = importdata("Acero_embuticion.txt")
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.')
回答(1 个)
Sulaymon Eshkabilov
2023-10-26
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');
fprintf('%3.5f \n', transpose(pendiente))
% An alternative way of storing the data is to use save()
save('Out_pendiente2.mat', pendiente)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!