Effacer les filtres
Effacer les filtres

How can I put Excel data into the function?

1 vue (au cours des 30 derniers jours)
민제 강
민제 강 le 14 Juil 2021
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by