Reading the data from one m file in another m file
조회 수: 10 (최근 30일)
이전 댓글 표시
Hey guys,
I would like to create two functions:
function model = CreateModel()
function sol=CreateRandModel(model)
In the function CreateModel I'd like to include all the informations about the model, It should be a structure with Matrix m (which is read from the csv file), times t1-t4 generated by myself and some interpolation data y1-y50 (in total structure with 55 fields)
I wrote a code:
function model = CreateModel()
%reading the data
%reading all parameters (t,interpolations....)
m=readtable('Fuel_arrivaltime.csv');
t1 = 0.7:0.01:0.85;
t2 = 0.72:0.01:0.86;
t3 = 0.68:0.01:0.83;
t4 = 0.70:0.01:0.86;
and the y: from y1 till y2 are described with the interpolation functions:
y1 = interp1(m.AFR256(2:7),m.AFR256_1(2:7),t1,'linear');
y2 = interp1(m.AFR256(2:7),m.AFR256_2(2:7),t1,'linear');
etc.
But the problem is that I don't know how to code it properly to make it readable in another m.file (function sol=CreateRandModel(model)) - where the input data should be the data from the model.
at the end of the
function model = CreateModel() I wrote:
model.m=m;
model.t1=t1;
model.t2=t2;
model.t3=t3;
model.t4=t4;
model.y1=y1;
model.y2=y2;
etc.
and at the beginning of the
function sol=CreateRandModel(model)
t1=model.t1;
t2=model.t2;
t3=model.t3;
t4=model.t4;
y1=model.y1;
y2=model.y2;
But after compilation it shows that there is not enough input arguments, I feel like the second file can't read the informations from the first one.
댓글 수: 0
답변 (1개)
Voss
2022년 4월 30일
Maybe you need to call CreateRandModel at the end of CreateModel?
function model = CreateModel()
% ...
model.m=m;
model.t1=t1;
model.t2=t2;
model.t3=t3;
model.t4=t4;
model.y1=y1;
model.y2=y2;
% ...
CreateRandModel(model)
and maybe do something with the output from CreateRandModel too.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!