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 ?

回答(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 CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by