Effacer les filtres
Effacer les filtres

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

6 vues (au cours des 30 derniers jours)
Kai Men
Kai Men le 23 Jan 2024
Modifié(e) : Aquatris le 23 Jan 2024
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 commentaire
Kai Men
Kai Men le 23 Jan 2024
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.

Connectez-vous pour commenter.

Réponses (2)

Aquatris
Aquatris le 23 Jan 2024
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 commentaires
Kai Men
Kai Men le 23 Jan 2024
Modifié(e) : Kai Men le 23 Jan 2024
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 le 23 Jan 2024
Modifié(e) : Aquatris le 23 Jan 2024
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.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 23 Jan 2024
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.

Catégories

En savoir plus sur Sources dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by