clear all, close all, clc
figpath = '../figures/';
addpath('./utils');
%% generate Data
polyorder = 5;
usesine = 0;
sigma = 10; % Lorenz's parameters (chaotic)
beta = 8/3;
rho = 28;
n = 3;
x0=[-8; 7; 27];
range2 = [((10^3.6)*.001), ((10^3.7)*.001) , ((10^3.8)*.001) , ((10^3.9)*.001) , ((10^4)*.001)]
for i = range2
tspan=[.001:.001:i];
N = length(tspan);
options = odeset('RelTol',1e-12,'AbsTol',1e-12*ones(1,n));
[t,x]=ode45(@(t,x) lorenz(t,x,sigma,beta,rho),tspan,x0,options);
for j=1:length(x)
dx(j,:) = lorenz(0,x(j,:),sigma,beta,rho);
end
dx_n0 = (dx);
Theta_n0 = poolData(x,n,polyorder,usesine);
m = size(Theta_n0,2);
total_n0(i,:) = [dx_n0 Theta_n0];
end
I currently have the above code but am receiving the error "Index in position 1 is invalid. Array indices must be positive integers or logical values.". Is it possible to run this code through the range of values and save each resulting dataframe separately?

댓글 수: 4

Ameer Hamza
Ameer Hamza 2020년 3월 19일
How is the function lorenz defined?
Kevin Egan
Kevin Egan 2020년 3월 19일
function dy = lorenz(t,y,sigma,beta,rho)
dy = [
sigma*(y(2)-y(1));
y(1)*(rho-y(3))-y(2);
y(1)*y(2)-beta*y(3);
];
From running the code without total_n0(i,:) = [dx_n0 Theta_n0]; there doesn't seem to be an error. It appears that the code runs through the entire range and saves the final (10^4)*0.001 from tspan
Ameer Hamza
Ameer Hamza 2020년 3월 19일
I also don't have function poolData, but from your description in comment, the error seems to be related to dimensions of dx_n0 and Theta_n0.
Kevin Egan
Kevin Egan 2020년 3월 19일
Yes, if I could possibly align the results side by side, that would be ideal. Although the length of the matrix would be unequal.
The resulting total_n0 would initially have 59 columns, therefore I'd like to add the next matrix to the 60th column.

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

답변 (1개)

Harsha Priya Daggubati
Harsha Priya Daggubati 2020년 3월 23일

0 개 추천

It would be more helpful, if you could copy the entire error message you get while posting the question in the forum. I guess the issue might be with the value of 'i'. You can make use of breakpoints to debug the issue much easily.
If that's no the case other workaround would be to possibly define 'total_n0' to be a cell array, to store variable length arrays.
total_n0{i} = [dx_n0 Theta_n0];
Hope this helps!

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 3월 19일

답변:

2020년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by