MATLAB Simulink scope with text in X axis - matlab

I need to make graphs, where X axis is a date and Y is a value. All calculations are made using Simulink. The problem is that scopes display default Simulink time in their X axis. Is there anything I can change, to make described graphs?

You can use plot function to get the desired graph with day of the month on the x-axis. The Graph can be for a particular month.
Example:
For the Month of May and dates 1st, 7th, 14th and 28th-
x=[1 7 14 28];
>> y=[2 10 3 1];
>> plot(x,y)
However, you need to make sure you import the data into 'y' variable correctly (from simulation output variable) so that it corresponds to your x-axis date-wise data.

Related

Plot time series data in MATLAB

I have to plot a time series data in MATLAB. The Y axis is a parameter taken six hourly for each day in a certain month of the year. And 44 such years have been taken into account. From 1958 to 2001. So the points on the X axis are 4*31*44=5456. How can I plot the data efficiently in MATLAB? The data file has two column vectors.
I have to plot the x axis so that it shows 44 July s from 1958 to 2001 . Each July has 124 points.
One for the time points (5456 points) so 5456 rows and other for the parameter measured. Thanks a lot.
As you don't give any more details, it is hard to know exactly what you are asking. If you have a matrix A with two columns, then you are looking for
plot( A(:,1), A(:,2) )
Alternatively, perhaps you want to see the histogram, hist, or the scatter plot scatter.
Well your X-axis(time data) is most probably not in datetime format & hence the problem.Once that is done, the plot will show what you want. You should try and change it to datetime & then try
plot(X,Y)
or
plot(A(:,1),A(:,2))
whichever be your data format

Using XTickLabel in plotting

I am implementing a Matlab script in which I would like to plot a function as follows:
figure;
plot(Flows(:,1),Flows(:,2));
title(strcat('f',num2str(j),'\_2013\_0',num2str(k)));
xlabel('Timestamp');
ylabel('Energy flow');
set(gca, 'XTickLabel', datestr(Flows(:,1)));
Flows is a matrix which takes as input a csv file where the first column is a Timestamp value. There are 12 files, each one for every month. In a loop, I read the files and create the matrix.
Flows(i,1)=datenum(Input{i,1}{1,1},'YYYY-mm-DD HH:MM:SS');
Flows(i,2)=Input{i,1}{1,7};
However, when I plot the trend the x axis only shows date from 1st of January 00:00 until 1st of January 00:36. How could I display in the x axis, at least, from 1s of "Month" until the end of the month? I suspect the problem comes from the mask of the translation of the data from num to date, but I have tried several masks, which one is the suitable?
Finally, I've added these lines:
set(gca,'XLim',[min(Flows(:,1)) max(Flows(:,1))]);
set(gca,'XTick',Flows(:,1));
set(gca, 'XTickLabel', datestr(Flows(:,1)));
But, when I'm going to plot the trend, I get the following Exception,
Values must be monotonically increasing

Plot two timeseries with different x-axis

I really can't find a solution to this:
I need to plot a timeseries of three years daily data on the same plot as three years monthly data (same y-scale = euros), but tried all the other threads talking about this without being able to figure it out. Any help?
It would be nice if the x-axis said the months, but numbers are just fine if it's too complicated...
thanks
A
How about this?
t = 1:365*3; %// example without leap year
y = randn(size(t)); %// example data
plot(linspace(1,37,numel(t)),y) %// x axis with 36 month periods
xlim([1,37])
set(gca,'xtick',1.5:4:37) %// ".5" to place tick at middle of each month
set(gca,'xticklabel',{'Jan','May','Sep'})

Set number of labels on my x-axis

Today I'm having problems with the x-axis in MATLAB. I plot some daily quantities together with the dates.
quantline= plot( quantDates(1:end,1), quantwithdrawn, '-.b', 'LineWidth', 2) ;
BUT it doesn't matter what combination of datetick, set gca, xlim, etc. I try, the best x-axis numbering I can manage is:
I want at least 3 months for every year, how can I fix this?

Matlab- How to plot waveform selected by threshold value. (by fetching data from array) and plotting it

20 wave forms fetched out of 1000I wanted to fetch waveform from array.
I am using following code.
clc
clear('all');
close('all');
Load ('w.mat'); % w.mat is actually file holding 1000 wave forms)
x= 1:length(w(1,:));
Subplot(321);
Plot(x,w(1:20,:)); %Plotting First 20 wave forms out of 1000
Now by visually looking at plot I found out that 0.6 is X axis threshold and about 15 point mark is the Y axis Threshold ( I would have posted picture here but i am new to stack flow forum it is not allowing me to post it).
How can I fetch waveforms on basis of X Axis threshold of 0.6 and Y axis Index value of about 15. and stored them in different files.
I know Save command to save it into a file on basis of different arguments assigned to it. But How to access X Axis and Y Axis values and compare the waveforms.
I wanted to compare to wave 2 actually which is more close , any too high values i have to avoid.
Any help Idea, as I am from C++ background. Matlab is a bit new to me.
Thanks Heaps
Kind Regards
K Haroon
I suppose what you are asking is how can we save the data whole value is greater than 0.6 on the x-axis and 15 on the y-axis
you can store the data/matrix in a variable by using
data=load('filename.txt')
and then applying a condition on its variables and then store them in a text-file using
dlmwrite('filename.txt',extracted_data_array)
if that's what you are asking