I have a struct with 85 fields. I want to copy data from the fields into a matrix called "one". Here is my code:
one=nan(85,2);
fields=fieldnames(s);
for i = 1:numel(fields)
len=find(s.(fields{i})==0)/4;
one(i)=s.(fields{i})(len-1,3:4);
end
This generates the "in an assignment A(:) = B" error. If I remove the subscript 'i' from 'one' it works, but then it overwrites the data on each loop, instead of storing it.

 採用された回答

Adam
Adam 2015 年 11 月 5 日
編集済み: Adam 2015 年 11 月 5 日

0 投票

one(i,:)=s.(fields{i})(len-1,3:4);
should work if I understand the problem correctly. Judging by your pre-sizing I assume the right-hand side of that equation is a 1-by-2 array which needs to be assigned to something of the same size on the left-hand side using row and column indices.

1 件のコメント

Cary
Cary 2015 年 11 月 5 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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

製品

タグ

質問済み:

2015 年 11 月 5 日

コメント済み:

2015 年 11 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by