Null matrix removal in the the output of the structure answer
2 ビュー (過去 30 日間)
古いコメントを表示
A(1).f1=[1 2 3 4]'; A(2).f2=[3 4 5 6]'; A(3).f3=[5 3 2 1]'; A(4).f4=[7 8 2 4]';
A(1).avg=A(1).f1+A(2).f2+A(3).f3+A(4).f4;
After above operation I have seen,
>> A.avg
ans =
16
17
12
15
ans =
[]
ans =
[]
ans =
[]
I dont want these null matrix in the result.. I need just
>> A.avg
ans =
16
17
12
15
What I have to do ?
0 件のコメント
回答 (2 件)
Doug Eastman
2011 年 2 月 5 日
It might be helpful to understand a little bit about what you are trying to do because there may be a more efficient way to do this, but to answer your question directly you can simply use:
[A.avg]
This will combine all the outputs into one array, since only one is non-empty that's what you get.
0 件のコメント
Walter Roberson
2011 年 2 月 5 日
As you know you have only defined A.avg for the first structure array element, index it directly: A(1).avg
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!