making dataset 3D data function

1 回表示 (過去 30 日間)
MA Tonima
MA Tonima 2020 年 1 月 9 日
回答済み: Ridwan Alam 2020 年 1 月 9 日
I have 48 variables with 267000*40 elements. I want to make this into datasets that looks like
  1. 267000*40*48
  2. 267000*48=> for this one I want to find the mean of the rown and do the same thing as before.
My question is how do I make a function that gives me this without having to do it individually:
this is what I know I should do for each variable
function [data]=datacreate(input)
A=input;
A(isnan(A))=0;
meanA=mean(A,2);
data(:,2)=meanA;
but when I want to do it all at once for all 48 variables, how am I to do this?
function [data]=datacreate(input1,...,input48) %is this notation correct?
for i=1:48 % can this be done without for loop?
A=input; % unsure here, should it be inputi?
A(isnan(A))=0;
meanA=mean(A,2);
data(:,i)=meanA;
i=i+1;
end
data;
Any kind of help is appreciated. Thank you.

採用された回答

Ridwan Alam
Ridwan Alam 2020 年 1 月 9 日
Let's assume your variables are named as 'input01', 'input02', ... 'input48'.
my3Ddata = [];
myMeanData = [];
varnames = whos('input*');
for v = 1:length(varnames)
currInput = eval(varnames(v).name);
currInput(isnan(currInput)) = 0;
my3Ddata = cat(3,my3Ddata,currInput);
currMean = mean(currInput,2);
myMeanData = [myMeanData, currMean];
end
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by