Calculating means ect from cell structure

11 ビュー (過去 30 日間)
Christoph Bauer
Christoph Bauer 2011 年 8 月 10 日
Hello everyone,
I have a beginners question on working with structures. I use a structure (called csvFiles in this example) with deeper levels name and Q: csvFiles.name.Q In my example csvFiles containes 12 entries so it would be a 1:12 struct. I want to do simple statistical operations like calculating mean, std or diff on every entrie stored in Q and write the result into the structure in a new entry called stat: csvFiles.stat
I tried the follwoing skript:
e=1:length(csvFiles);
for k = 1:e
mean=mean([csvFiles(1:e).name.Q])
[csvFiles.stat.mean]=mean
end
This only gives me an entry in the first entry of csvFiles, for the rest it leaves an empty matrix. Can somebody explain me how to solve this?
Thank you

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 8 月 10 日
You overwrote the function mean with a variable with the same name, don't do that.
From the second iteration mean(...) will be considered a variable being indexed and not a function applied to (...).
Your loop could be rewritten as:
for k = 1:e
[csvFiles.stat.avg] = mean([csvFiles(k).name.Q])
end

その他の回答 (1 件)

Christoph Bauer
Christoph Bauer 2011 年 8 月 31 日
thank you very much

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by