Filling cell array in specific date domains

4 Ansichten (letzte 30 Tage)
HaDu
HaDu am 29 Jul. 2017
Kommentiert: per isakson am 9 Aug. 2017
Hi, I am really new in Matlab and coding so I hope somebody can help me. I have a cell array where the first column is the start time and the 2nd is the endtime (dd.MM.yyyy_HH:mm:ss) and some other columns with further information called GivenData.
I have another cell array (eq. 170000x180), which is a SQL-Database-import. The 2nd column here is the time of documentation the others are further information.
(i made the array smaller for testing purpose)
at this point i generated empty columns at the end of the Database, which I want to fill in the right time domains
For Example: GivenData(2,3) should be written in Database(5:10,173) GivenData(2,4) should be written in Database(5:10,174) end so on
GivenData(3,3) should be written in Database(29:35,173) GivenData(3,4) should be written in Database(29:35,174)
for every row in GivenData the Database should get every information in the right time domain.
I usually wiold just do a bunch of for loops. But I have the feeling this is not that easy with matlab, besides it would take the whole night to fill the database.
I tried something like that
for k=2:size(GivenData,1)-1
ta=datetime(GivenData(k,1), 'InputFormat','dd.MM.yyyy_HH:mm:ss');
te=datetime(GivenData(k,2), 'InputFormat','dd.MM.yyyy_HH:mm:ss');
for L=2:size(GivenDB,1)-1;
tlower=datetime(GivenDB(L,2),'InputFormat','dd.MM.yy HH:mm:ss.SSSSSS');
tupper=datetime(GivenDB(L+1,2),'InputFormat','dd.MM.yy HH:mm:ss.SSSSSS');
if(isbetween(ta,tlower,tupper)==1)
ta=L;
break
end
for m=2:size(GivenDB,1)-1;
tlower=datetime(GivenDB(L,2),'InputFormat','dd.MM.yy HH:mm:ss.SSSSSS');
tupper=datetime(GivenDB(L+1,2),'InputFormat','dd.MM.yy HH:mm:ss.SSSSSS');
%
if(isbetween(te,tlower,tupper)==1)
te=L;
break
else
te=size(GivenDB,1);
for n=3:size(GivenData,2)
p=rowstart+1:size(GivenDB,2);
GivenDB(ta:te,p)=GivenData(k,n);
end
end
end
end
end
Basically I tried to find out the in which row my start time begins and in which it ends to fill this. But it seems I cant have multiple variables. So basically I have nothing. I would really appreciate if someone had some suggestions.
I hope I could explain the problem well enough.
  3 Kommentare
HaDu
HaDu am 30 Jul. 2017
Hi John BG
basically this is right. I want the data GivenData(:,3:10) written in the right time domains of the other cell array (Database).
So if my first line has the starttime (Auftragsbeginn) 01.01.2017_ 00:15:33 and the end time (2nd column) 01.01.2017_17:22:01, I want all the following colums of this row written for all columns (additional data from GivenData) and rows (every matching time), where the timestamp (2nd column of database) is in this time range.
If I was doing this with for loops, I would need one loop for the starttime and endtime and another loop für every row in the database. But I dont know how I can tell matlab to do this.
for k=2:size(GivenData,1) %variable to run through GivenData
L=2:size(GivenDB,1)-1 %viariable to run through GivenDB
t=datetime(GivenDB(L,2),'InputFormat','dd.MM.yy HH:mm:ss.SSSSSS'); %time from database to compare
ta=datetime(GivenData(k,1),'InputFormat','dd.MM.yy_HH:mm:ss'); %start time
te=datetime(GivenData(k,2),'InputFormat','dd.MM.yy_HH:mm:ss'); %endtime
if isbetween(t,ta,te)
GivenDB(......
this is really difficult to describe. additionally english isnt my first language, so sorry for the hard time here.
I hope I could clarify your question.
per isakson
per isakson am 9 Aug. 2017
"[...] bunch of for loops. But I have the feeling this is not that easy with matlab" How come you think for-loops are not as easy in Matlab as in any other language.
"it would take the whole night to fill the database." for-loops are not that slow in Matlab.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 30 Jul. 2017
‘GivenData(2,3) should be written in Database(5:10,173) GivenData(2,4) should be written in Database(5:10,174) end so on’
You are copying one value in ‘GivenData’ to a column of values in ‘Database’. Use the repmat function to create it.
Example
Database(5:10,173) = repmat(GivenData(2,3), numel(5:10), 1);
Database(5:10,174) = repmat(GivenData(2,4), numel(5:10), 1);
You will probably have to loop through the row number ranges, since I do not know how you are creating or augmenting ‘Database’.
If I understand correctly what you want to do, this should get you started.
  2 Kommentare
HaDu
HaDu am 30 Jul. 2017
Thanks! This will save me probably the for-loop to fill the information in the Database. Unfortunately I have no idea how to get to this point
Star Strider
Star Strider am 30 Jul. 2017
My pleasure!
If you want to find specific times in one data set that correspond to times in another data set, consider using one of the set operation functions, such as ismember (link), ismembertol, or others.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

HaDu
HaDu am 9 Aug. 2017
Nobody who can help me out here? I am in a really bad spot here. I would really appreciate some help :|.
  1 Kommentar
per isakson
per isakson am 9 Aug. 2017
Your chances to get a useful answer increases if you upload files with sample data. Screen-clips are less useful.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting Matrices 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!

Translated by