フィルターのクリア

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 日間)
Pratik Anandpara
Pratik Anandpara 2017 年 3 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.
  2 件のコメント
Pratik Anandpara
Pratik Anandpara 2017 年 3 月 22 日
編集済み: Pratik Anandpara 2017 年 3 月 22 日
1. change system name with sys
2. fitfun chng with fitfund1
Pratik Anandpara
Pratik Anandpara 2017 年 3 月 22 日
編集済み: Pratik Anandpara 2017 年 3 月 22 日
please sir shown with codes changes in fuction file ?

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 件のコメント
Pratik Anandpara
Pratik Anandpara 2017 年 3 月 22 日
when run this file i want output in workspace is direct
formbus
tobus
value in output
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