How to concatenate 3 columns into one in a Matlab Table? - matlab

I have a Matlab table with three columns: Year, Month, Day.
I want to make it into one column that represents the date in a format 'MM/dd/yyyy'. How can I do that? I tried quite a while to no avail, but I believe someone may know it immediately.

Suppose you have a table with three columns with your values. As your table must contain the same type of data, you must first make sure that your values for the month, day and year are in the string format. If they aren't, convert them into strings (use B(:,1)=int2str(A(:,1)) for example)
Once your data in the string table, concatenate them in a 4th column.
for i=1:length(B(:,1))
B(i,4)=strcat(B(i,1), "/", B(i,2), "/", B(i,3));
end

Related

Conditional formatting google sheets, match date between two dates- mark that row that is matching

I am looking for a way to match any date in a column of dates with a bunch of start/end periods at columns next to it. If any match, mark my cell.
I have managed to do this for one row, but I would like it to look at a whole column (or set range ex X6-X10) and compare with a bunch of date-periods in two columns.
Any one with any ideas of how I can do that?
This is what I have come up with so far:
And I am using this formula:
=AND($X$6>=$R$6,$X$6<=$T$6)
But, as I said, this only works for one row today. I would like to look through all rows in the columns.
This formula should work:
=COUNTIFS(X$6:X,">="&R6,X$6:X,"<="&T6)

How to remove table data based on comparison between different columns in another table in MATLAB?

I have 2 tables in MATLAB- table A and table B, each having different dimensions (different no. of rows and columns). The first column of table A has the Date and time in format like 2018-11-01 12:00:00 (DateTime data format).
Now, in Table B, the Third and Fourth Column also consist of Date and Time in format like 2018-11-01 01:11:12:173000. What I would like to achieve is to remove all the rows (which are the data instances) from Table A, in case of which the Datetime for Table A falls in the range between the Date and Time in Table B. (To be more precise, suppose Table B has an entry of DateTime in third column for the first row/first data instance as 2018-11-10 12:30:00:173 and in fourth column as 2018-11-10 12:40:00:145, I would like to remove all data entries/rows from Table A, in case of which the DateTime Column value for Table A falls in the range of 2018-11-10 12:30:00:173 to 2018-11-10 12:40:00:145, as an example). This means that basically I would be removing the data in the aforesaid range from the Table A.
To approach this, the first thing which comes to my mind is to use inner join(), but, it is evident from Mathworks Community guidance that innerjoin() only matches the exact column value which I specify the Key as, but in this case, I would be looking at a range of DateTime values in 2 columns of table B, so perhaps this might not be the best approach. Using a for loop for this purpose might as well work, but would be quite complex and redundant with huge computational time on the large data in the tables. Any help in this regard would be highly appreciated.
I received some good answers to the question on the Mathworks Community page and the answers can be found at https://uk.mathworks.com/matlabcentral/answers/432509-how-to-remove-table-data-based-on-comparison-between-different-columns-in-another-table-in-matlab?s_tid=prof_contriblnk
I appreciate the answer by Guillaume (answered on the Mathworks Community page link mentioned above) and am putting it down here for future help to anyone:-
%inputs: TableA with a column named date, TableB with a column named datestart and dateend
%replace by actual table and variable names.
datetocheck = repmat(TableA.date, 1, height(TableB)); %replicate in as many columns as there are rows in B
datestart = repmat(TableB.datestart', height(TableA), 1); %tranpose and replicate in as many rows as in A
dateend = repmat(TableB.dateend', height(TableA), 1);
toremove = any(datetocheck >= datestart & datetocheck <= dateend, 2);
TableA(toremove, :) = [];

How to extract information meeting a specific criterion from a table?

I have a table with 6 columns and 140,000 rows, and I can't figure out how to extract specific information from the table. For instance, when I try to extract all the accidents that happens on a specific date, either it tells me that the row '12/05/2015' does not exist or it doesn't let me set 'Date' as a Row Name since the dates repeat because more than one accident happens in a day, thus giving me the error that 'Duplicate row name: '01/01/2015'.
How can I pick a date and extract all of the data that corresponds to it?
P.S. Below you can see two photos, one of the table and one of the errors I get when trying to set date as a row to make everything clearer.
if I understand correctly your matter, you want to extract from the table, the rows that contain Date1, if so try this :
new_table = table(table(:,1)==Date1,:);

Expression to create SSRS column dynamically

I need an expression to take an existing column and recreate this column over and over before another column/s where the column name contains either "Monday" or the date of the column falls on Monday.
The reason I need this expression is to repeat a header column in a pivoted report that is pivoting start/enddate parameter. So if a user selects to run the report for this month, they should get 31 columns (for each date/day) and header repeating before every Monday.
Make sure your dataset contains all the dates in your date range. If not create a date table and cross join to it. Don't pivot the results, let SSRS do that bit. Once your dataset has all the dates, you can use a matrix in your report and drop the date colum into the column group. This will give you one column for each date in your dataset. I'm not at my PC at the moment but if you need any more help, show an example of your dataset and I'll put together a quick sample report.

Retrieving value from previous row in calculated column based on condition

I am working on data in Spotfire. The table has 4 columns:
RowID
StudID
IMT
Date
I am trying to insert a calculated column in Spotfire to get the date from the previous row for a specific StudID. The date should not be filled for first entry for a specific StudID since it does not have a previous row.
Please refer to the image for details:
This will be a calculated column using the OVER function, along with Intersect, Previous and the First aggregation.
First([Date]) OVER Intersect(Previous([Date]), [StudID])
It reads: over the intersection between (group of) the previous (to the current row) dates (which are the same) and the Student ID's (the same as the current row), give me the first row of that group. In your example, it will only ever return one date for that group, but the formula needs to be able to handle what happens if there are multiple rows. You may also need to think about whether this will happen in your data and what you're going to do about it. I.e.
StudID Date
124-639 6/12/2018
124-639 6/12/2018
124-639 6/14/2018
Building off of JasonJ's answer, it looks like his solution ran into issues when the dates of different StudIDs overlapped with one another.
So I was seeing something along the lines of this:
StudID, Date, Result
A, 10/1/2014,
A, 10/10/2014, 10/1/2014
A, 10/17/2014, 10/10/2014
B, 10/20/2014,
A, 10/21/2014,
B, 10/22/2014,
B, 10/24/2014, 10/22/2014
I created a weird workaround by adding another Calculated Column.
I doubt this is the IDEAL way to do this (I'd bet there's a better OVER function, but I couldn't identify it right off), but it looks like it's working.
First Calculated Column (Named [CalcRank]):
Rank(Concatenate([StudID],Year([Date]),If(DayOfYear([Date])<10,"0",""),If(DayOfYear([Date])<100,"0",""),DayOfYear([Date])))
Second Calculated Column:
Max([Date]) OVER (Intersect(Previous([CalcRank]),[StudID]))
Please note, you may have to pad your StudID with 0s to make sure it orders properly, like I did with the Date column.