How to fix the code

1 回表示 (過去 30 日間)
gjashta
gjashta 2019 年 12 月 10 日
回答済み: Star Strider 2019 年 12 月 10 日
I have the code below but I am geting an error:Index exceeds the number of array elements (1).
N=length(DATA(:,1))
for i=1:N
x=DATA(1,i)
stations(i).station_number = x(1);
stations(i).month = x(2);
stations(i).day = x(3);
stations(i).price = x(4);
stations(i).quantity = x(5);
end

採用された回答

Star Strider
Star Strider 2019 年 12 月 10 日
If you want to set ‘N’ to the row size of ‘DATA’, this is preferable:
N = size(DATA,1);
Perhaps you intend to read the entire row, so that would change ‘x’ to:
x=DATA(1,:)
that would work with the rest of the loop.
Since we have no idea what ‘DATA’ is, we can only guess at a solution.
Note that there are likely much more efficient ways of doing what the code you posted does.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by