Clear Filters
Clear Filters

Null matrix removal in the the output of the structure answer

2 views (last 30 days)
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 ?

Answers (2)

Doug Eastman
Doug Eastman on 5 Feb 2011
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 on 5 Feb 2011
As you know you have only defined A.avg for the first structure array element, index it directly: A(1).avg

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!