Azzera filtri
Azzera filtri

Null matrix removal in the the output of the structure answer

2 visualizzazioni (ultimi 30 giorni)
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 ?

Risposte (2)

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

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by