The values from the for loop won't store on the array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Imanol Fernandez de arroyabe Zabala
am 26 Okt. 2023
Beantwortet: Sulaymon Eshkabilov
am 26 Okt. 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 Kommentare
Torsten
am 26 Okt. 2023
Except for some Inf values in "pendiente", everything works out fine (see above).
Dyuman Joshi
am 26 Okt. 2023
Bearbeitet: Dyuman Joshi
am 26 Okt. 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.')
Antworten (1)
Sulaymon Eshkabilov
am 26 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!