MATLAB: How to upload a txt file to solve a function multiple instances at once

file upload into a function

I have a function that calls for 6 inputs and then has several equations within it and gives a single integer as the answer.
function [ maxStress ] = momentStress(w, x, Bw, Hw, Bf, Hf)
I need to upload a .txt file with a 5×6 array that so my output is 6 different [maxStress] values. How do you do this?

Best Answer

I suppose you mean 5 different outputs since the function needs 6 inputs (6 columns),
data = dlmread('filename.txt');
maxStress = zeros(1,size(data,1));
for k = 1:size(data,1)
maxStress(1,k) = momentStress(data(k,1),data(k,2),data(k,3),data(k,4),data(k,5),data(k,6));
end
you have to adjust the function inputs with corresponding right column indices.