필터 지우기
필터 지우기

how can i make matlab select a value for a vector variable from a set of data

조회 수: 5 (최근 30일)
i am doing optimization design model that compare the fuel consumption of different diesel engines.
so, i have excel sheet contains the MCR of different diesel engines from manufactureres.
i have defined a variable MCR and i want matlab to assign a value for MCR from the values of MCR data that stored in excel sheet
i want that to be done automatically every time the optimization algorithm run a new attempt.
what is the function i should use to assign the value of MCR from the created set of data?

채택된 답변

darova
darova 2020년 2월 19일
Use xlsread
MCRdata = xlsread('data.xls'); % read data from excel file
MCR0 = MCRdata(5); % assign 5th value
  댓글 수: 4
Nourhan Elsayed
Nourhan Elsayed 2020년 2월 20일
my model has the following variables
m = 3; % ''for examble'' m is the number of installed main engines per one propulsion train
j = 4 % ''for examble'' j number of modes of operation
x = sym ('x', [m j]); %x is the loading of main engine number m at j mode of operation
assume (x >= 0);
assumeAlso (x<=1);
thus, x is a symbolic matrix variable of size m x j
i have used this function to define MCR as an array of size 1x3
MCR = sym('MCR', [1 m]) % MCR of engine with index m
and the below function defines MCR data set
MCRdata = [250; 450;1500;900;2500;2000;1750]
my objective is to make the model choose a value for MCR from the MCRdata, no matter the order. Then, this value of MCR goes through a series of functions and calculations later on.
So, MCR is a symbolic variable whos value is assigned automatically from a defined MCRdata
darova
darova 2020년 2월 20일
What about this trick?
MCRdata = [250; 450;1500;900;2500;2000;1750];
ix = randi(length(MCRdata),1,length(MCR));
MCR = sym( MCRdata(ix) );
[ix' MCR]

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by