Info

此问题已关闭。 请重新打开它进行编辑或回答。

i have one function file and m file now i give values of x(1) and x(2) in function file which update in m fille and run

1 次查看(过去 30 天)
function y=fitfund1(x) %for this we give two values of x(1) and x(2)
sys= xlsread('IEEEE1.xlsx'); %this is excel file
sys(x(2),7)=sys(x(2),7)-x(1);
sys %this updated value excel file with x(1) and x(2)
lflow1 % this is mfile which run with this "system' excel sheet
end
now lflow1 is mfile which is run with that updated system excel sheet
frombus = sys(:,1)';
tobus = sys(:,3)' ;
when run this code system is unknown for this vaue

回答(2 个)

ES
ES 2017-3-22
1. dont use system in our code. system is a keyword in MATLAB intended to do something else.
2. and fitfun is a function. so the value in system is visible to its workspace only. This will not be accessible by lflow1.
So a) either make lflow1 as a function and pass 'system1' to it. or b) make fitfun to write value of 'system1' into base workspace so that lflow1 can access it as you have done now.

ES
ES 2017-3-22
编辑:ES 2017-3-22
Solution 1: a) make lflow1 as a function and pass 'sys' to it.
.m
function y=fitfund1(x) %for this we give two values of x(1) and x(2)
sys= xlsread('IEEEE1.xlsx'); %this is excel file
sys(x(2),7)=sys(x(2),7)-x(1);
sys %this updated value excel file with x(1) and x(2)
lflow1(sys) % this is mfile which run with this "system' excel sheet
end
lflow1.m
function lflow1(sys)
frombus = sys(:,1)';
tobus = sys(:,3)' ;
end
  4 个评论
ES
ES 2017-3-22
Please try solution 2.make fitfun to write value of 'system1' into base workspace so that lflow1 can access it as you have done now.
.m
function y=fitfund1(x) %for this we give two values of x(1) and x(2)
sys= xlsread('IEEEE1.xlsx'); %this is excel file
sys(x(2),7)=sys(x(2),7)-x(1);
sys %this updated value excel file with x(1) and x(2)
assignin('base', 'sys', sys) %This creates a variable with name sys in base workspace with the same value of sys calculated above
lflow1 % this is mfile which run with this "system' excel sheet
end
lflow1.m [This remains as you had done originally. Since sys is now available in workspace, lflow1 can access sys, and frombus and tobus will also be available in the workspace.]
frombus = sys(:,1)';
tobus = sys(:,3)' ;

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by