Plotting data sets of different lengths from a struct - avoid padding - matlab

I hope this is a simple enough question, but I am a beginner and haven't managed it on my own after several sessions.
I have a 1x29 struct of financial market data with 8 fields: stock_market.
the first field is the date
As you can see, not all the components of the stock market i.e. the stocks have the same length time series (some comanies are newer than others or have since left the market etc.)
I would like to know in general how best to manipulate such an uneven struct of time series data. One specific example is that I'd like to write a function that can extract the 'Date' and 'AdjClose' (adjusted closing price) from the struct, for one individual stock, and plot that on a graph, with the dates shown/labelled on the x-axis and prices on the right. An extension is to plot several AdjClose time series on one x-axis together, even though the length of their respective Date values are different. I don't want to pad these strings out so that I have lines running along zero for a portion of the graph.
Other more complicated functions shouldn't be difficult once I could manage this task.
I haven't shared any code, as it is simply 'plot(stock_market(1).Date, stock_market(1).AdjClose)` and mostly red with errors. I have read a few discussions about padding, but like i mentioned above, don't want to pad with zeros or any other number for the diagrams. For other functions, I may have to pad them, but if anyone has a different solution - it'd be great to hear it :-)
Thanks in advance.

Related

How do I plot one measure per axis in Tableau?

I have a problem that I have reduced to its essence with the following CSV file. Imagine we're a company that sells potatos and apples, and each customer is assigned a potato-class and an apple-class.
What I want is to plot the sales according to class - so apple sales by apple class and potato sales by potato class, in one diagram. Dragging all the measures into a workheet, I get this:
So I would like an overlay of the top left and bottom right classes.
If I combine everything into one diagram via dual axis, I get this:
So Tableau is plotting potato sales and apple sales on both the potato and the apple class axis, creating four dots per class where I want two.
Does anyone have an idea on how to basically assign one measure to one axis instead of both measures to both axes? (Hiding the "wrong" dots would also be fine).
Also, I realize that pivoting the dataset to have fields "sales", "class" and "product" would solve the problem, but reality is of course far more complicated than this toy example and it's just not feasible.
Thanks!
You'll likely have an easier time if you reshape your data first, say to have the following columns "Customer,Item,Class,Amount" -- so each row in your original data set would yield 2 rows in the transformed version of your data set. Tableau Prep can make those types of transformations easy (and repeatable), but it is possible to do something similar in Tableau Desktop alone (using a self-union and some calculated fields).
So the first 2 lines might be:
Customer,Item,Class,Amount
1,"Apple",1,2
1,"Potato",1,4
Either way make sure Class is treated as a dimension in Tableau.
Data wranglers often call this a tall format instead of a wide format.

Power BI | Combine Measures into one VIsual

Alright - After completely checking google and all the forums I now really need help.
The Situation:
There are two measures. One shows the "SUM" (222) and the other shows the "SUM%" in % (2,81%)
If I show the each measures in an separate card visual, everything is fine
The Need:
Combine these two measures into one card visual
The Problem:
When I combine these two measures with "&" or "COMBINEVALUES", the % value completely freaks out and shows "2,80550992038418e-02". Yes, the Measure is formatted as percentage and limited to two decimal value places
Sounds easy - But seems impossible. Any Ideas? For now I need to combine only two measures - but maybe there is an solution to combine even more than only two measures?
Goddamnit! Sometimes the solution is so simple...
COMBINEDMEASURENAME = CONCATENATE([MEASURE 1], CONCATENATE(" (", FORMAT([Measure2WITH%], "0.00%)")))
With the FORMAT-Function you can override the format of the measure and define it to fit your needs

Modeler question: Is there a function in SPSS for multiple 'if' statements? Forecasting dates

I am trying to build a forecast for interest expense for floating debt in my company.
I have been given a set of ResetDates which help me match a given rate based on when the ResetDate is.
I have been successful in forecasting one period, but I need a much longer set of periods to satisfy my requirements.
I've tried derive nodes and nested if statements as well as filler nodes.
I am given this data to work with, I can only look at one ResetDate ahead.
Here you will find the data I used: Columns A/B/C/D is what i'm given, Column E (or 5th column from left to right) is what I want to derive as my output
I want to use 'InterestPayDate' and derive:
if it's more than 'NextReset' , the add 90 days to the 'NextReset' to create 'NextReset2'
That is as far as I can get.... where my problem lies is I want to look at NextReset2 and derive:
if 'InterestPayDate' is more than 'NextReset2', then add 90 days to 'NextReset2', if it's less than 'NextReset2', keep the current value for 'NextReset2'
Output should look like Column E here
Not sure if I need to dig deeper into the logical functions, in all honesty, I've just picked up SPSS and I am really trying to learn. Hopefully, you can point me in the right direction.
Thank you.
After computing the first NextReset2, you need to use a Filler node like the one below to change the value of the field.
You might need more than one identical nodes like this - one for each potential 90-day period that you are looking to extend the NextReset2 date. In your sample data, you will need at least two Filler nodes to get the correct value of NextReset2 for the last of the records.
There might be a more elegant way to do it, but this will work and it's easy enough to make copies of a node and string them together like this.
Please also see a sample IBM SPSS Modeler stream showing this approach here and using your sample data.

Tableau Dual Axis with different filters

I am trying to create a graph with two lines, with two filters from the same dimension.
I have a dimension which has 20+ values. I'd like one line to show data based on just one of the selected values and the other line to show a line excluding that same value.
I've tried the following:
-Creating a duplicate/copy dimension and filtering the original one with the first, and the copy with the 2nd. When I do this, the graphic disappears.
-Creating a calculated field that tries to split the measures up. This isn't letting me track the count.
I want this on the same axis; the best I've been able to do is create two sheets, one with the first filter and one with the 2nd, and stack them in a dashboard.
My end user wants the lines in the same visual, otherwise I'd be happy with the dashboard approach. Right now, though, I'd also like to know how to do this.
It is a little hard to tell exactly what you want to achieve, but the problem with filtering is common.
The principle that is important is that Tableau will filter the whole dataset by row. So duplicating the dimension you want to filter won't help as the filter on the original dimension will also filter the corresponding rows in the second dimension. Any solution has to be clever enough to work around this issue.
One solution is to build two new dimensions that use a calculation rather than a filter to create the new result. Let's say you have a dimension, [size] that has a range of numbers from 1 to 10 and you want to compare the total number of rows including and excluding the number 5. You could create a new field using a formula like if [size] <> 5 then 1 else 0 end
Summing the new field will give a count of the number of rows that don't contain a 5 and this can be compared directly to a rowcount of the original [size] field which will give the number including the value 5.
This basic principle can be extended to much more complex logic. The essential point is to realise that filters act on every row in your data and can't, by themselves, show comparisons with alternative filter choices on a single visualisation.
Depending on the nature of your problem there may be other solutions worth looking at including sets and groups but you would need to provide more specific details for users here to tell you whether they would be useful.
We can make a a set out of the values of the dimension and then place it in the required shelf. So, you will have your dimension which will plot accordingly and set which will have data as per the requirement because with filter you can't have that independence of showing data everytime you want.

Merge sensor data for clustering/neural net usage

I have several datasets i.e. matrices that have a 2 columns, one with a matlab date number and a second one with a double value. Here an example set of one of them
>> S20_EavesN0x2DEAir(1:20,:)
ans =
1.0e+05 *
7.345016409722222 0.000189375000000
7.345016618055555 0.000181875000000
7.345016833333333 0.000177500000000
7.345017041666667 0.000172500000000
7.345017256944445 0.000168750000000
7.345017465277778 0.000166875000000
7.345017680555555 0.000164375000000
7.345017888888889 0.000162500000000
7.345018104166667 0.000161250000000
7.345018312500001 0.000160625000000
7.345018527777778 0.000158750000000
7.345018736111110 0.000160000000000
7.345018951388888 0.000159375000000
7.345019159722222 0.000159375000000
7.345019375000000 0.000160625000000
7.345019583333333 0.000161875000000
7.345019798611111 0.000162500000000
7.345020006944444 0.000161875000000
7.345020222222222 0.000160625000000
7.345020430555556 0.000160000000000
Now that I have those different sensor values, I need to get them together into a matrix, so that I could perform clustering, neural net and so on, the only problem is, that the sensor data was taken with slightly different timings or timestamps and there is nothing I can do about that from a data collection point of view.
My first thought was interpolation to make one sensor data set fit another one, but that seems like a messy approach and I was thinking maybe I am missing something, a toolbox or function that would enable me to do this quicker without me fiddling around. To even complicate things more, the number of sensors grew over time, therefore I am looking at different start dates as well.
Someone a good idea on how to go about this? Thanks
I think your first thought about interpolation was the correct one, at least if you plan to use NNs. Another option would be to use approaches which are designed to deal with missing data, like http://en.wikipedia.org/wiki/Dempster%E2%80%93Shafer_theory for example.
It's hard to give an answer for the clustering part, because I have no idea what you're looking for in the data.
For the neural network, beside interpolating there are at least two other methods that come to mind:
training separate networks for each matrix
feeding them all together to the same network, with a flag specifying which matrix the data is coming from, i.e. something like: input (timestamp, flag_m1, flag_m2, ..., flag_mN) => target (value) where the flag_m* columns are mutually exclusive boolean values - i.e. flag_mK is 1 iff the line comes from matrix K, 0 otherwise.
These are the only things I can safely say with the amount of information you provided.