필터 지우기
필터 지우기

Why does my Nx2 matrix turn into a 1x1 when I pass it into a MATLAB Function block

조회 수: 6 (최근 30일)
So I want to change the values in a reservoir dynamically per second, but since I cannot have input ports I tried to change it via changing the variable value the parameter is referencing. So I tried indexing my Nx2 matrix to change the value as time passes by the second, but when I pass the 'From workspace' block into the MATLAB Function block, a constant error of index error appears, telling me 'Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.'
The index used was [idx, 2], idx being the time used for indexing, since my data has 'time in seconds' and 'temperature'.
Is there a way to fix this? Or is my approach wrong to begin with? Thanks in advance!
  댓글 수: 1
Kai Men
Kai Men 2024년 1월 23일
For reference, I am trying to change reservoir_temperature and reservoir_RH which are referencing variables T_env and RH_env using data collected and interpolated to have data every second.

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

답변 (2개)

Aquatris
Aquatris 2024년 1월 23일
Your matrix you are getting from workspace needs to be Nx3 in your case, where the 1st colum is time, 2nd and 3rd column are your actual data.
Or instead of using a matrix variable, use a structure variable as described in the block itself.
  댓글 수: 2
Kai Men
Kai Men 2024년 1월 23일
편집: Kai Men 2024년 1월 23일
Hi, just for clarification, I have 2 Nx2 matrix, corresponding to time&temperature, and time&RH, does this mean I should combine it all into a Nx3 matrix with time, temp and RH?
Aquatris
Aquatris 2024년 1월 23일
편집: Aquatris 2024년 1월 23일
Correct, x = [time temperature RH]; should do the trick.
Make sure the time vectors of your 2 Nx2 matrices are identical before combining them into a Nx3 matrix. Otherwise you should either use 2 'from workspace' blocks and combine the data via a 'mux' or you should interpolate to achieve same time vectors for both before combining them in order to have sensible results from your simulation.

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


Walter Roberson
Walter Roberson 2024년 1월 23일
When you use From Workspace, then the first column of the data is treated as the time, and the remaining columns of the data are treated as values over time.
So when you have your 2 x 2 matrix, the first column is being treated as the time, and the second column is being treated as scalars at the times given by the first column.

카테고리

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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by