Calculate the summation of matrices within a cell
1 view (last 30 days)
Show older comments
Hello
I know this is an easy question but I am a bit stuck
I have generate a set of data which I am storing into structures. Then I calculate a quantity over them. My problem is two parted, first i tried to save them into a new structure but it did not allow me, so I stored them into a cell array (which worked perfectly)
In the next loop want to calculate the summation of the available matrices inside the array for a given {n}
field_names = fields(HsD1); %structure field_names2 = fields(TpD1); %structure
for n=1:11%size(field_names2)
pause(0.01)
P=([])
fn2=char(field_names2{n})
fn =char(field_names{n})
% contourf((((TpD1.(fn2).*(HsD1.(fn).^2))./1000)),colorbar %check visually if it works
P=((((TpD1.(fn2).*(HsD1.(fn).^2))./1000));
Pow(n)=P
% Pow=([])
% Pow(n)=P % This does not work
%
end
then the addition should be
for i=1:11
Average=[]
Average{n} = sum(Pow{n})/11
end
The matrices are 200x200 and I would like to add all together (matricewise), each point represent a different day. That is why all the point in all the matrices have to added and averaged.
How is this possible to be done? I also tried the cell2str command to convert my cell array into structure but no luck, I would prefer if I could save Pow in a structure from the start
thank you
0 Comments
Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!