Reading the data from one m file in another m file

조회 수: 10 (최근 30일)
Bartosz Bagrowski
Bartosz Bagrowski 2022년 4월 30일
답변: Voss 2022년 4월 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.

답변 (1개)

Voss
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.

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by