How to write this loop?

4 visualizaciones (últimos 30 días)
MB
MB el 16 de Dic. de 2019
Comentada: Rena Berman el 16 de En. de 2020
%% 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
  5 comentarios
Adam Danz
Adam Danz el 18 de Dic. de 2019
Rena Berman
Rena Berman el 16 de En. de 2020
(Answers Dev) Restored edit

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
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
Walter Roberson
Walter Roberson el 16 de Dic. de 2019
That would be correct for running the code.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by