Concatenation of multiple variables into one variable

2 ビュー (過去 30 日間)
Jassim Abubacker
Jassim Abubacker 2015 年 5 月 6 日
コメント済み: Michael Haderlein 2015 年 5 月 6 日
I do have multiple variables in .mat file. Size of each variable is 1x33376. I need to concatenate all the variables into one variable, Then exclude the NaN values and find the mean of all values vertically.

回答 (2 件)

Michael Haderlein
Michael Haderlein 2015 年 5 月 6 日
Assuming that the mat file contains only these variables:
data=cell2mat(struct2cell(load('filename.mat')));
meanvals=nanmean(data);
  2 件のコメント
Michael Haderlein
Michael Haderlein 2015 年 5 月 6 日
Please response as comment to keep the thread readable (the order of answers might change over time).
--------------------------
Answer by Jassim Abubacker moved here:
Thank you..
In my mat file, I do have files named A_... and B_....I need to find seperate mean for both excluding Not A Number (NaN).
I got the following error, when I tried the code.
Error in ==> Variablemerging1 at 1 data=cell2mat(struct2cell(load('OutA2011.mat')));
Can you please help me?
Michael Haderlein
Michael Haderlein 2015 年 5 月 6 日
Now, should the variables be concatenated or do you want the mean for every variable? nanmean will ignore NaN, so something like
nanmean([nan 1 2;3 nan 4])
will return [3 1 3].
If you want the mean of every single variable, then you want the mean of the second dimension, right (as the size in first dimension is 1, mean does not make too much sense). So if you want the mean for each variable, just use
meanvals=nanmean(data,2);

サインインしてコメントする。


Jassim Abubacker
Jassim Abubacker 2015 年 5 月 6 日
Thank you..
In my mat file, I do have files named A_... and B_....I need to find seperate mean for both excluding Not A Number (NaN).
I got the following error, when I tried the code.
Error in ==> Variablemerging1 at 1 data=cell2mat(struct2cell(load('OutA2011.mat')));
Can you please help me?

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by