在Matlab中使用连续矩阵(Using consecutive matrices in Matlab)
我正在创建一个在分析工作室中使用多个矩阵的函数。
矩阵的名称相同,名称中有日期参考(月份和年份:nov-1956是matrix5611 ,dec-1956是matrix5612 ,jan-1957是matrix5712 ,依此类推,直到1999年底。
对于每一个,每个月/每年的平均值之间应该进行比较(取决于您关注的研究领域)。
我正在尝试使用一些循环来改变输入矩阵的名称,而不是按日期手动编写,但是一个有用的函数。
任何想法或有用的功能?
I'm creating a function to use multiple matrices in an analysis studio.
The matrices are given with the same name with a date reference in the name (month to month and year to year: nov-1956 is matrix5611, dec-1956 is matrix5612, jan-1957 is matrix5712, and so on until the end of 1999.
For each one there should be a comparison between the mean value of each month/year (depending of what area of study are you focused on).
I'm trying to use some loops to vary the name of the input matrix instead of write manually date by date, but a function that helped would be useful.
Any idea or useful function?
原文:https://stackoverflow.com/questions/10487872
2020-02-23 22:02
满意答案
如果您的数据位于不同的矩阵中,则可以使用eval将平均值存储到某个矩阵,在本例中为MeanMatrix ,其中Y维度为年,X维度为月份:
编辑:它不是从5611运行的数字,但是yymm ...
编辑:似乎矩阵不是从1956年1月开始,而是从1956年11月开始。
% add here missing months matrix index strings.
MissingMatricesCellArray = {'5601', '5602', '5603', '5604', '5605', '5606', '5607', '5608', '5609', '5610'};
% MissingmatricesCellArray = {};
for Year = 56:99
for Month = 1:12
NumString = sprintf('%02d%02d', Year, Month);
% calculate and store means only for matrices that are not missing.
if ~(ismember (cellstr(NumString), MissingMatricesCellArray))
MeanMatrix(Year,Month) = mean(mean(eval ([