How to write this loop?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%% readDataFromFile and WriteDataToFile are given functions
%% stress.out is a file containing a matrix of 195 elements
function calculateStressVonMises('stress.out')
readDataFromFile('stress.out');
sigmaV_matrix = [];
for c = 1: 1: 194
i = 2
j = 3
k = 4
sigmaV(c) = sqrt((c(i))^2 - (c(i))*(c(j)) + (c(j))^2 + 3*(c(k))^2);
sigmaV_matrix = [sigmaV_matrix; {sigmaV}];
writeDataToFile('stress.out', sigmaV_matrix)
end
Respuestas (1)
Walter Roberson
el 16 de Dic. de 2019
%% readDataFromFile and WriteDataToFile are given functions
%% stress.out is a file containing a matrix of 195 elements
function calculateStressVonMises(filename)
if ~exist(filename, 'var'); filename = 'stress.out'; end
data = readDataFromFile(filename);
sigmaV = sqrt(data(:,2).^2 - data(:,2).*data(:,3) + data(:,2).^2 + 3*data(:,4).^2);
writeDataToFile('stress.out', sigmaV)
end
There is a possibility that the last line should instead be
writeDataToFile('stress.out', num2cell(sigmaV,2) )
1 comentario
Ver también
Categorías
Más información sobre Linear Algebra 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!