Error in table row subscript
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Matt J
2024-2-15
编辑:Matt J
2024-2-15
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 个评论
Matt J
2024-2-15
编辑:Matt J
2024-2-15
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!