how to get the last value of a cell

37 Ansichten (letzte 30 Tage)
Peihong
Peihong am 26 Aug. 2013
Dear Friend,
I generated a series of N by 1 cells with different lengths. I want to generate a new vector, each element of this vector is the last value of the cells.i.e the first value of this vector is the last value of the first cell, the second value of this vector is the last value of the second cell, and so on. anyone can advise me how to achieve this?
  1 Kommentar
Image Analyst
Image Analyst am 26 Aug. 2013
Bearbeitet: Image Analyst am 26 Aug. 2013
What type/class of variable is in the cells? Characters? double arrays? Structures? Scalar integers?
Have you checked out cellfun()?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Peihong
Peihong am 26 Aug. 2013
Hi, Walter,
would you please give more information. my problem, I want to find zscores for 100 time series data points. but the difference is I divide this time series into two parts, for instance, the first 50 as a group, I calculate the zscore for this 50 data points. then,I calculate the zscore for 51 data points, length 51, then take the last zscore of first 51 data points, add this zscore to the first 50 zscores, so the original zscore series length becomes 51, then, continue this process. here is the code, would you please have a look
n=length(data(:,2));
rolling=50;
rollingSuprise=zeros(n,1);
rollingSuprise(1:rolling)=zscore(data(1:rolling,2));
temp=cell(n-rolling,1);
for i=1:n-rolling
temp{i}=zscore(data(1:rolling+i,2));
end

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 26 Aug. 2013
NewVector = cellfun(@(v) v(end), YourCellArray)

Peihong
Peihong am 26 Aug. 2013
thanks. it works

Community Treasure Hunt

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

Start Hunting!

Translated by