Info

This question is closed. Reopen it to edit or answer.

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 view (last 30 days)
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

Answers (2)

ES
ES on 22 Mar 2017
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 on 22 Mar 2017
Edited: ES on 22 Mar 2017
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 Comments
ES
ES on 22 Mar 2017
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)' ;

This question is closed.

Community Treasure Hunt

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

Start Hunting!