Trajectory =1:15;
%TrajDetail = zeros(328,4,15);
for i = 1:length(Trajectory)
TSPANtf = [ 0 t(i) ] ;
%TSPANtf2 = [ 0 t_corrected_2 ] ;
RelTol = 3.e-14 ; AbsTol = 1.e-16;
Options = odeset('RelTol',3.e-14,'AbsTol',1.e-16);
[tt,xx] = ode113(@(t,x) CRes3BP_xy(t,x,mu),TSPANtf,x0_corrected(i,1:4)',Options);
plot(xx(:,1),xx(:,2),'k',xx(:,1),-xx(:,2),'k')
pause(0.01) ;
hold on
axis equal
pos_x = xx(:,1);
pos_y = xx(:,2);
vel_x = xx(:,3);
vel_y = xx(:,4);
TrajDetail (i)= table(pos_x,pos_y,vel_x,vel_y); %here the comes as (see below the italised stuff)
end
% I have not taken the tt values out but still i need
what I wanted to do is get the values of xx and tt for each iteration and store in a table named TrajDetail 1,TrajDetail 2 ...TrajDetail 15.
Note that xx changes the row size according to "tt"
eg: Iteration 1 may cause xx to have 160 x 4 ; Iteration two may have 200 x 4 etc
table should become like Table1 (ieTrajDetail 1) containg
tt;pos_x;pos_y:vel_x;vel_y and has to be done for each iteration
Error for above
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported. Use a row subscript and a variable
subscript.

댓글 수: 1

Rik
Rik 2019년 4월 3일
Tables are 2D in Matlab, containing numbered rows and named columns. If you want something else, you can't use a table. You could use a double array to create a single large multidimensional array, or encapsulate it in a cell array.

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

 채택된 답변

Rik
Rik 2019년 4월 3일
편집: Rik 2019년 4월 3일

0 개 추천

A bold guess based on your commented code:
Trajectory =1:15;
TrajDetail = zeros(1,4,15);
for i = 1:length(Trajectory)
TSPANtf = [ 0 t(i) ] ;
%TSPANtf2 = [ 0 t_corrected_2 ] ;
RelTol = 3.e-14 ; AbsTol = 1.e-16;
Options = odeset('RelTol',3.e-14,'AbsTol',1.e-16);
[tt,xx] = ode113(@(t,x) CRes3BP_xy(t,x,mu),TSPANtf,x0_corrected(i,1:4)',Options);
plot(xx(:,1),xx(:,2),'k',xx(:,1),-xx(:,2),'k')
pause(0.01) ;
hold on
axis equal
TrajDetail (1:size(xx,1),:,i)=xx(:,1:4);
end

댓글 수: 8

This doesnt wrok I have checked this before posting even
Rik
Rik 2019년 4월 3일
Then the height of xx is not 328. If you share all the variable needed to run this code I can propose an actual fix, for now I'll edit my code to expand the array to the size of xx on the first iteration.
The variables requiered are t and x0_corrected are attached
Rik
Rik 2019년 4월 4일
Changing the evaluated function to @(t,x) t*x as a placeholder, this runs without error. What is it exactly that makes you conclude it doesn't work for you?
This works and have tried before submitting original question, I just wanted the output as table format for documentation. I guess its not possible . I retain to classic.
Rik
Rik 2019년 4월 4일
As I mentioned before tables are 2D. Unless you convert your 3D array down to 2D (which is certainly possible to do), you will not be able to store the data as a table.
Rik is correct but perhaps this needs some more explanation.
Tables contain "variables", which need not be column vectors (that's why they are referred to as "variables" and not as "columns"). So if your data are 3D, NxMxP say, one way to store them is in an NxM table, each variable of which is itself NxP. Or as an NxP table with NxM variables.
Another way to store NxMxP data in a table is by flattening to 2-D as an (N*M)xP table, and then add an extra "indicator variable" to keep track of what 2nd dim slice each row corresponds to.
And finally, if all your data are numeric, just store as an NxMxP numeric matrix.
Thank you both Rik and Peter.

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

추가 답변 (1개)

Guillaume
Guillaume 2019년 4월 3일
편집: Guillaume 2019년 4월 3일

0 개 추천

You could store your 15 tables into a cell array,
Trajectory = 1:15;
TrajDetail = cell(size(Trajectory));
for i = 1:numel(Trajectory) %I recommend using numel instead of length
%... your code as is
TrajDetail{i} = table(pos_x,pos_y,vel_x,vel_y);
end
However, you may be better of using just one table with an extra column indicating which iteration the trajectory came from:
Trajectory = 1:15
TrajDetail = [];
for i = 1:numel(Trajectory)
%... your code as is
trajindex = repmat(i, size(pos_x, 1), 1);
TrajDetail = [TrajDetail; table(trajindex, pos_x,pos_y,vel_x,vel_y)]
end
By the way, instead of
pos_x = xx(:,1);
pos_y = xx(:,2);
vel_x = xx(:,3);
vel_y = xx(:,4);
something = table(pos_x,pos_y,vel_x,vel_y);
You could just write:
something = array2table(xx, 'VariableNames', {'pos_x', 'pos_y', 'vel_x', 'vel_y'});

댓글 수: 2

"All tables in the bracketed expression must have the same variable names." error message ,
I assume that error comes from my 2nd example, where I store everything in just one table. I've fixed a typo in the repmat of that code.
You certainly can't get that error from my 1st example.

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

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

제품

릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by