struct for loop syntax difficulty

Not sure what I'm doing wrong with the following loop:
for p=66:1:95;
Site(p).Day = Data((Data(:,4) == p),:)
end
I want Site(p) to contain all data from only the days (in column 4) that I am looking for, which should give a 1x29 struct, but at the moment Site(p) is a 1x95 struct where the first 65 entries are blank ([]). I assume the problem is in the first line, but when I make p the correct size (eg p=1:29) I get an error message about dimension mismatch. Also, if I set another vector, eg n=95-66 and p=1:n, I get the same error message. I can't see what I'm doing wrong.

 採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 11 日

0 投票

Site(p-65).Day = Data((Data(:,4) == p),:)

2 件のコメント

Sara
Sara 2013 年 11 月 11 日
??? Subscript indices must either be
real positive integers or logicals.
Sara
Sara 2013 年 11 月 11 日
I've got it to work with your solution now. Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2013 年 11 月 11 日

コメント済み:

2013 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by