フィルターのクリア

How can I put Excel data into the function?

1 回表示 (過去 30 日間)
민제 강
민제 강 2021 年 7 月 14 日
回答済み: Walter Roberson 2021 年 7 月 14 日
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!

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 14 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by