Error in table row subscript
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
falling at the last hurdle - I've tried to include as much information as I can!
I've got what I need MatLab to do working in the workspace, but when it goes into the loop I can't figure out how to make the row extraction (? sorry if not the right thing to call it) correspond to the
i
variable .
In the loop of MPC_DICE its set up i as a dynamic state variable,
i = x(1)
and
i_next = i+1
, so i increases with every loop.
I've written the code that works when using integers but I need it so the row being called = i, if that makes sense.
Northpopulation = readtable("LN_NEXTGROWTH.csv");
LN = [];
LN = Northpopulation.LNORTH(1);
which is exactly what i need it to do and works great, but when I replace 1 with i
Northpopulation = readtable("LN_NEXTGROWTH.csv");
LN = [];
LN = Northpopulation.LNORTH(i);
I get this message:
Error using tabular/subs2inds A table row subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, a cell array of character vectors, or a pattern scalar.
Error in tabular/dotParenReference (line 105) rowIndices = t.subs2inds(rowIndices,'rowDim',subsType.forwardedReference);
(i) is being used in other parts of the code as a variable, where i=1 etc... and works fine, i just can't figure out how to make it work with calling the correct row.
5 commentaires
Réponses (1)
Matt J
le 15 Fév 2024
Modifié(e) : Matt J
le 15 Fév 2024
In what way is this not what you want?
Northpopulation = readtable("LN_NEXTGROWTH.csv");
%LN = []; <-----You don't need this
x=[5,2 7, 10];
for j=1:numel(x)
i=x(j)
LN = Northpopulation.LNORTH(i)
end
2 commentaires
Matt J
le 15 Fév 2024
Modifié(e) : Matt J
le 15 Fév 2024
I combined all the code as below. Also, I don't know if you were aware, but you can run code right here in these forum posts. So, that's what I did below and the output shown is from that.
I don't recognize what casadi.MX variables are, but it doesn't look like they correspond to any numeric value. They are just symbols. Because of that, it is not clear what row indexing rule you want them to obey. If i=x, as shown below, which row in Northpopulation.LNORTH is that supposed to correspond to?
websave('MPC-DICE.zip',['https://github.com/cmkellett/MPC-DICE/archive/master.zip']);
unzip('MPC-DICE.zip');
addpath([pwd '/MPC-DICE-master']);
websave('casadi.tar.gz',['https://github.com/casadi/casadi/releases/download/3.5.5/casadi-linux-matlabR2014b-v3.5.5.tar.gz']);
untar('casadi.tar.gz','casadi');
addpath([pwd '/casadi']);
import casadi.*
x = MX.sym('x');
i=x
i_next=i+1
whos i i_next
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!