Array isn't being correctly indexed?

2 ビュー (過去 30 日間)
Sarah Gomez
Sarah Gomez 2022 年 3 月 6 日
コメント済み: Image Analyst 2022 年 3 月 8 日
T = 10;
numpoints = 1000;
%1:1000:10, so from 1 to 10 I want 1000 points in between
for i = 1:numpoints:T
T1(1,i) = i;
end
disp(T1);
When I try and run this code I just get 1, when I'd like one large row vector or array that goes from 1:numpoints:T, so a large row vector. Any help is greatly appreciated.

回答 (1 件)

Image Analyst
Image Analyst 2022 年 3 月 6 日
After the first increment T = 1 + 1000 = 1001 which is more than 10 so the loop only iterates once. You want linspace()
Tmax = 10;
numpoints = 1000;
%1:1000:10, so from 1 to 10 I want 1000 points in between
T = linspace(1, Tmax, 1000);
for k = 1:length(T)
T1(1,k) = T(k);
end
disp(T1);
  1 件のコメント
Image Analyst
Image Analyst 2022 年 3 月 8 日
@Sarah Gomez did that solve your problem or not?

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by