Null matrix removal in the the output of the structure answer

2 ビュー (過去 30 日間)
Raviteja
Raviteja 2011 年 2 月 5 日
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 ?

回答 (2 件)

Doug Eastman
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.

Walter Roberson
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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by