필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by