Table and Array Indexing using loops

조회 수: 2 (최근 30일)
Lui
Lui 2019년 3월 23일
댓글: Walter Roberson 2019년 5월 7일
Hi everyone,
I have a challenge in indexing in a for loop.
I have a 696 by 2 table with a date identifier. This is as captured below. I would like to create a [648 4] from the [696 2] using the date identifier or otherwise.
I would like to create a new table such that
i=24;
n=numel(24:1:648);
H=zeros(n, 3);
for N=1:n
for i=24:648
i=[(i-days(1):days(1):i+days(2))]
% yields for me a new matrix for i=[GHI([i-day(1) i i+day(1)]
% which then gives me [648 3]
i=i+1;
end
H(N,:)=table2array(hvalues(i,2:4));
end
Any help on the above is highly appreciated.
  댓글 수: 9
dpb
dpb 2019년 5월 7일
What's the specific error text (all the red from the command line in context)???
I'd have to wrap my head around the original Q? again to remind myself but there's nothing specifically wrong with the expression other than one has to ensure that i-48 is >=1 and newdata hasn't been previously defined as a noncormant size that this vector won't fit into...but functionally, it's the same idea, yes, and "it will work" given the constraints of where it is attempted are legitimate.
Walter Roberson
Walter Roberson 2019년 5월 7일
We do not know which version of the code was being used, so we do not really have any useable context for thinking there is an error.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2019년 3월 24일
The aim is to increase the sample size of my data by sampling the data at 24 hours intervals.
why didn't you say that in the first place? That's a typical case of XY problem. You want to do something, don't know how to do it but think it can be done one way so ask about that way. Except that's not how it's done.
The simplest way to resample timed data is to convert your table into a timetable then use retime to resample it to whichever interval you want
hvalues = table2timetable(hvalues);
newvalues = retime(hvalues, 'daily', 'linear'); %resample at 24 hours interval using linear interpolation
However, I'm a bit confused, your data is hourly so I'm not sure how resampling in 24 hours interval is going to increase the sample size.
  댓글 수: 1
Lui
Lui 2019년 3월 25일
This gives me hourly values which I can easily retrieve. But I appreciate as this helps me elsewhere.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by