3 Excel COLUMNS x,y,z imported into work space as vectors, z is a function of x,y how do i get the data into a 2d lookup table

조회 수: 1 (최근 30일)
Hi all, im sure this has been answered but i cant seem to find an answer to what is probably a simple answer. 3 columns of data, x,y,z
z is a function of x,y. im inporting the data as 3 vectors. i can seem to get it into the correct form for a look up table in simlink, My end goal is to be able to interpolate for any x,y input and get an aproxamated output for z,

채택된 답변

Jon
Jon 2021년 11월 22일
편집: Jon 2021년 11월 22일
Here is an example MATLAB script that you could run to assign the necessary variables in your base workspace before running your Simulink model. The idea is that you have to make a two dimensional array, where the rows correspond to your x values in your Excel Sheet and the columns the y values in your Excel Sheet, with the elements given by your third, z, column in your spreadsheet.
% script to put 2D look up table into base workspace before running Simulink
% read in the three columns of data from Excel, third column is function of
% first two
T = readtable('look2.xlsx');
% sort the rows of the table so that z values will be columnwise values of
% m by n look up array
T = sortrows(T,{'y','x'});
% find the unique x and y entries to be used for looking up values in two d
% array in Simulink
x = unique(T.x);
y = unique(T.y);
% determine the dimension of the look up array
m = numel(x); % number of unique x entries
n = numel(y); % number of unique y entries
% make 2d look up array Z to be used in Simulink from the z column
Z = reshape(T.z,m,n);
  댓글 수: 3
Jon
Jon 2021년 11월 22일
I am running R2021b.
There isn't too much in my example model. We could probably figure out how to make one that you can open but here are some key screenshots.

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

추가 답변 (1개)

stephen collier
stephen collier 2021년 11월 23일
Thanks Jon,
That works well, however when i substitute my own data i get a reshape error, error snip attached.
  댓글 수: 3
Jon
Jon 2021년 11월 23일
By the way, I just noticed you put your response in as an answer. Since your entry was not actually an answer but a response to an answer it would be better in the future to put this type of response in as a comment and just keep one thread.
stephen collier
stephen collier 2021년 11월 23일
Thank you Jon,
your explanation has given me greater understanding of how the look up table works, it is possible to limit x and y their relationship is linear, x is an irridance plot any y is a temperature value. ill need to find another method

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

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by