The values from the for loop won't store on the array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Imanol Fernandez de arroyabe Zabala
le 26 Oct 2023
Réponse apportée : Sulaymon Eshkabilov
le 26 Oct 2023
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 commentaires
Torsten
le 26 Oct 2023
Except for some Inf values in "pendiente", everything works out fine (see above).
Dyuman Joshi
le 26 Oct 2023
Modifié(e) : Dyuman Joshi
le 26 Oct 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.
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.')
Réponses (1)
Sulaymon Eshkabilov
le 26 Oct 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');
fprintf('%3.5f \n', transpose(pendiente))
% An alternative way of storing the data is to use save()
save('Out_pendiente2.mat', pendiente)
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!