How to apply arrayfun for multiple column
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BISWA BHUYAN
am 28 Okt. 2019
Bearbeitet: BISWA BHUYAN
am 29 Okt. 2019
Dear all, I am using following code for the one column in a data matrix. however, I have 60 columns and 6892 rows in the data matrix. How to apply the collowing code on the all columns, please suggest.
n = 6892; % total number of rows
m = 100; % window size
h = arrayfun(@(k)genhurst(y(k:m+k-1)),1:30:(n-m+1),'UniformOutput',false); % 30 is the forward shifting size
HH=h.';
0 Kommentare
Akzeptierte Antwort
Guillaume
am 28 Okt. 2019
If you really want to use arrayfun you could do it like this:
windowsize = 100; %why call it m when window size is a lot clearer?
[rows, cols] = ndgrid(1:30:size(y, 1)-windowsize+1, 1:size(y, 2));
HH = arrayfun(@(row, col) genhurst(y(row:row+windowsize-1, col)), rows, cols, 'UniformOutput', false);
or you could just use an explicit loop which might be clearer and faster.
7 Kommentare
Guillaume
am 29 Okt. 2019
I made a silly mistake in the explicit loop code. I forgot to subtract the window size from startrows. It should be:
startrows = 1:30:size(y, 1)-windowsize+1;
same as in the ndgrid code.
As for your later code. You have loaded the data into a variable called data but then use date which happens to be a matlab function. Note that as I've replied, if you want to apply genhurst by month, the easiest is with:
data = readtable('data.xlsx');
monthly_data = groupsummary(data, 'Date', 'month', @genhurst)
or with retime.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!