필터 지우기
필터 지우기

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.
  댓글 수: 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