The values from the for loop won't store on the array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Imanol Fernandez de arroyabe Zabala
el 26 de Oct. de 2023
Respondida: Sulaymon Eshkabilov
el 26 de Oct. de 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 comentarios
Torsten
el 26 de Oct. de 2023
Except for some Inf values in "pendiente", everything works out fine (see above).
Dyuman Joshi
el 26 de Oct. de 2023
Editada: Dyuman Joshi
el 26 de Oct. de 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.')
Respuestas (1)
Sulaymon Eshkabilov
el 26 de Oct. de 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 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!