Plotting the data in the given file over time period and tabulating the results

I have a model with 10 states and I have frequency of each state over time. The data is stored in a cell array, where each cell of the array has 1x10 values, each value for one state(only for first time period I have 1x7 values). I have attached it in the mat file.
I want to do two things:
1) I want to plot these frequencies over the time time for each state. I am not sure how to do it because the data is in cell array.
2) I want to tabulate these frequencies and make it presentable so that I can document my results, but commands like tabulate(data) does not work.
Please can anyone help me in this?

 Réponse acceptée

I have no idea what you want the result to be.
Try this:
D1 = load('data.mat');
StateFrequency = D1.StateFrequency;
Col1 = NaN(10,1);
Col1(1:numel(StateFrequency{1})) = StateFrequency{1};
StateFreq = [Col1, cell2mat(StateFrequency(2:end))];
T1 = array2table(StateFreq);
FirstFiveVariables = T1(:,1:5)
figure
hold on
for k = 1:numel(StateFrequency)
plot(StateFrequency{k})
end
hold off
grid
figure
ribbon(StateFreq)
grid on
xlabel('Column')
ylabel('Frequency')
zlabel('Amplitude')
There are two plots, the first is a 2D line plot and the second is a 3D ribbon plot.
The ‘FirstFiveVariables’ table excerpt displays the first five variables in the table. It is not necessary for the rest of the code, and can be deleted.

4 commentaires

Dear Rider,
Thank you so much. This is exactly what I wanted for the task (2).
For the task 1(plot), I am attaching a figure. I want to have such a graph in which I can show how does the frequencies of each state(in figure there are five states (like divorce married etc.) vary over the time period.
My pleasure!
The states themselves are not labeled in the data (as best I can tell), so I have no idea how to plot them in that respect. I have no idea what either the row values or column values are.
This is as close as I can get to that:
x = 1:size(StateFreq,2);
figure
area(x, cumsum(StateFreq,2).')
or perhaps:
x = 1:size(StateFreq,2);
y = cumsum(StateFreq,2).';
figure
area(x, max(y)-y)
or perhaps:
x = 1:size(StateFreq,2);
y = cumsum(StateFreq,2).';
yalt = max(y)-y;
maxline = zeros(1,size(y,1));
figure
ha = area(x, max(y)-y);
for k = 1:numel(ha)
if ~any(isnan(ha(k).YData))
maxline = sum([maxline; ha(k).YData]);
end
end
hold on
patch([x, fliplr(x)], [maxline, ones(size(maxline))*max(ylim)],[1 1 1]*0.8)
hold off
xlim([min(x) max(x)])
I must defer to you to create that as you want it, since I have no idea what the data are.
See the documentation for the area function for details on how to use it. Experiment with the area and patch calls (specifically the colour) to get the result you want.
This is super helpful. Many thanks :)
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by