How can I put Excel data into the function?

2 views (last 30 days)
function [y] = rosensc(xx)
xx = [x1 x2 x3 x4];
for ii = 1:4
xxbar(ii) = 15*xx(ii) - 5;
end
sum = 0;
for ii = 1:3
xibar = xxbar(ii);
xnextbar = xxbar(ii+1);
new = 100*(xnextbar-xibar^2)^2 + (1-xibar)^2;
sum = sum + new;
end
y = (sum - 3.827*10^5) / (3.755*10^5);
end
I have Excel file about x1 x2 x3 and x4 value.
So I want to get 20 Y values about x1 x2 x3 x4.
Please let me know. Thank you!

Accepted Answer

Walter Roberson
Walter Roberson on 14 Jul 2021
format long g
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/683938/rosen20.xlsx';
data = readmatrix(filename);
h = height(data);
Y = zeros(h,1);
for K = 1 : h
Y(K) = rosensc(data(K,:));
end
Y
Y = 20×1
104221.223285056 18421.5879316538 12369.3018011083 14678.1935484914 6757.98685897914 770.00639995527 76930.949171674 107554.180109397 160124.763289724 13632.6698832972
function [y] = rosensc(xx)
for ii = 1:4
xxbar(ii) = 15*xx(ii) - 5;
end
sum = 0;
for ii = 1:3
xibar = xxbar(ii);
xnextbar = xxbar(ii+1);
new = 100*(xnextbar-xibar^2)^2 + (1-xibar)^2;
sum = sum + new;
end
y = (sum - 3.827*10^5) / (3.755*10^5);
end

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!