# Index exceeds the number of array elements (1).

31 ビュー (過去 30 日間)
Haya Ali 2021 年 4 月 20 日

clear all; close all; clc;
x1=11500.2;x2=11477.9;x3=11417.3;x4=11426.4;x5=11413;x6=11382.9;x7= 11375.1;x8=11347.9;x9=11351.1;x10=11329.30;
x = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10]
plot (t,x)
N_measurements=1;
N_basis=32;
index=randi([200000,300000],1,N_measurements);
Xdot=zeros([1,N_measurements]);
for ni=1:N_measurements
Xdot(ni)=(x1(index(ni)+1)-x1(index(ni)))/dt;
end
##### 1 件のコメント表示非表示 なし
Cris LaPierre 2021 年 5 月 26 日
Unrecognized function or variable 't'.

サインインしてコメントする。

### 採用された回答

Cris LaPierre 2021 年 5 月 26 日
It looks like Ch 5 of MATLAB Onramp would be helpful for you.
It is unclear to me what you are tryign to do. The issue is you are using indexing to extract a value from x1. x1 has 10 values in it, so you should be indexing using a number between 1 and 10. However, you create a random index number between 200000 and 300000 to extract a value from x1.

サインインしてコメントする。

### その他の回答 (1 件)

Daniel Bengtson 2021 年 5 月 26 日
You are attempting to access an index of x1 that does not exist.
index=randi([200000,300000],1,N_measurements);
assigns a random value between 200000 and 300000 to the variable 'index' which you then use to try to access data in x1 within your for loop.
x1(index(ni)+1)
Only x1(1) actually exists by your assigments, and your x1(index) is trying to access x1(200000)

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!