MATLAB date number too short - how to get MATLAB to stop shortening my Serial Date Number - matlab

I need to extract the dates from a set of data s.
I use the command s(x).comm.date where x can be changed for each person however it is returning the serial date number as 7.3244e+005 which just gives me the day but I need it to show much more detail something like this 732162.65994213.
I don't know if the data I have is already saving it as the shorthand format but it's a set of data from MIT and the help documentation shows it as the long hand format so I sincerely doubt this.
Yours,
MATLAB Newbie

Try typing the following help format or format long (for starters).
By default, Matlab displays 5 significant digits (calculations are done in appropriate floating-point precision, no matter how those variables are displayed). Refer to the documentation for different ways of displaying.

Related

Simulink: Plot Timeseries in a scope/block to visualize data

I have a Simulink block that calls a user-defined function. This function calls another function: thingspeakread.m (provided by the ThingSpeak Official Toolbox).
From here, I want two outcomes. Data (numeric type, vector), and timestamps (strings, vector).
[data,timestamps] = thingSpeakRead(___)
Now, I'm able to get the values of "Data" into a Scope without much of an issue (using coder.extrinsic('thingSpeakRead') and preallocating the variable to store such points). The issue I have is this: I need to make more sense of the data visualization, and for that purpose, I need to plot this "Data" against the information displayed in the timestamps vector. The timestamps varies per minute only.
What I'll try to do, but doesn't satisfies me a lot:
Convert the timestamp into a numeric value using datenum() using the format for 'mm/dd/yyyy HH:MM:SS'
This option sends back a huge number (which can be used to plot Data vs. Time indeed, but it doesn't look 'good' because the number is just too big and I don't like it).
I have thought about these too:
Convert date to Julian Date type.
Convert Hours, Minutes and Seconds into 3 different arrays.
But I don't see that getting me where I want (which is to plot Data vs. Time, being able to spot easily that the numbers displayed for "Time" are corresponding to an specific HH:MM:SS of a day).
Is there anything you can guys suggest, please? Thanks a lot in advance!
Edit 1: Can I use something like datetick() in Simulink?
What you are doing with converting to datenum is the only way to pass the "dates" down a Simulink signal.
There's no mechanism to display the time series, with dates displayed on the x-axis, without writing custom code.
If you don't need to display the time series as the simulation is running then just dump it to a mat file in your existing code, and generate the plot during post-processing.
If you want it to display as the simulation is running then you'll need to write a custom display block. This should be done as a Level-2 M-Code S-Function, but could be done using a MATLAB Function block. Either way you would input the datenum into the block and then convert the datenum back to a date - using something like datetime before generating the visualization, or afterwards using datetick.

Formula to add days to a Gregorian date

I was looking at Tomohiko Sakamoto's weekday calculator. It's a formula to calculate the day-of-week directly given year, month, day. That made me wonder what other neat date calculation shortcuts exist.
In particular, given an input date as (in_year, in_month, in_day) and a number of days N to add, what's a formula for returning the output (out_year, out_month, out_day)? Is there a well-known trick like the algorithm above?
One way would be to convert the input to a Julian day (a count of days since 4713 BC), add N to it, and then convert back. There are formulas for conversion in both directions. But the combined formula would be quite unwieldy. Is there a simplified version?
Perhaps there is even a formula to move forward or back by a certain number of weekdays.
This question isn't "how do I do date arithmetic in my favourite programming language?" I know how to call the date library to perform these operations. It's more curiosity and the hope of starting a collection of cool date algorithms.
Some of the answers in Algorithm to add or subtract days from a date? will be relevant to this. In particular http://howardhinnant.github.io/date_algorithms.html gives code to convert y,m,d to a count of days and back again. Those two routines run back to back would be pretty fast.

How to extract digits (number) using Matlab

At work I have to record a lot of data from png data. Every time I have to manually record the digits (e.g. mean\SD 101.1\11) on the excel sheet and read it with Matlab. Would it be possible that Matlab could directly read the digits from the PNG image, so that lots of work could be saved?
I know it might involve pattern recognition, but still hope that there may be someone who has done this before.
You can make use of Optical Character Recognition (OCR). The code for it is available here

Matlab MATPOWER Output in long format

I've been trying to use MATPOWER to do a power flow analysis for a network i have but all the outputs are coming with only 2 decimal places. Is there a way to configure the output to have the long format?
Trota,
You can modify the number of decimal places printed on screen or forwarded to the output text file.
If you browse the printpf.m file, simply change the required %9.xf to the required number of decimal places, where x is the number of digits after the decimal point. For bus data, these can be found at line 412 onwards.
Hope this helps.
You cannot change the number of decimal places used in the pretty-printed output of MATPOWER, but all of the results are available in full precision in the results struct returned by runpf() or runopf(). You can display these results with whatever precision you choose using standard Matlab commands such as disp() or fprintf().

gnuplot: how to use a*(10^b) format on axis

I am using really big numbers (milions) on my x-axis, so when I use
set format x %6.0f
I got big numbers like 25000000. That is quite nice, but takes much space, so there are only few labels and reader losts information.
When I exclude setting format, I get something like 2e+07, what is quite unfriendly and unusual to reader according to my opinion.
I would like format like 25*(10^6), so the number would be first and then multiplied by 10^n, or something very similiar to that. I think that would be the best solution, if the x-axis is long about 30000000 points or even more.
However, reading manuals, e.g. "How do I change the format of the numbers ?" from http://t16web.lanl.gov/Kawano/gnuplot/tics-e.html did not help me much.
Thank you in advance.
All format specifiers that gnuplot has to offer can be found here.
If you don't like the 2e+07 format you could try setting the format with
set format x "%.0s*10^{%T}"
which gives you a format like 15*10^6.
Also one can use the following to obtain scientific notation with cross symbol: 2x10^6
set format x "%2.0t{/Symbol \264}10^{%L}"