I am trying to plot a time-series graph using the data in my csv file.
my code is like:
[d,s]=xlsread('CSVLog_20220620_115817.csv')
x= s(:,1);
x1 =datenum(x,'HH:MM:SS')
y= d(:,105);
scatter(x1,y)
title('Time vs FCR_L/H')
xlabel ('Time')
ylabel ('FCR_L/H')
grid on
I got an error:
Error in linear_regression (line 3)
x1 =datenum(x,'HH:MM:SS')
Caused by:
Error using dtstr2dtnummx
Failed to convert from text to date number.
can someone helps?
Related
I am currently taking Andrew Ng's Stanford Machine learning course and am using MATLAB to complete the programming assignments despite being new to the MATLAB programming language as the course requires completion of assignments in either Ocatave or MATLAB. For the first programming assignment the course offers Octave/MATLAB script that steps you through the exercises. I am attempting to write a MATLAB function that will plot data for x and y variables, however, am continuing to run into the same error and am beginning to spin my wheels with finding a solution. I have a plotData.m file I am working off of and here is the code I have put together:
function plotData(x, y)
%PLOTDATA Plots the data points x and y into a new figure
% PLOTDATA(x,y) plots the data points and gives the figure axes labels of
% population and profit.
figure; % open a new figure window
hold on;
% ====================== YOUR CODE HERE ======================
% Instructions: Plot the training data into a figure using the
% "figure" and "plot" commands. Set the axes labels using
% the "xlabel" and "ylabel" commands. Assume the
% population and revenue data have been passed in
% as the x and y arguments of this function.
%
% Hint: You can use the 'rx' option with plot to have the markers
% appear as red crosses. Furthermore, you can make the
% markers larger by using plot(..., 'rx', 'MarkerSize', 10);
plot(x, y, 'rx');
xlabel('population (in tens of thousands)');
ylabel('profit (in $10,000s)');
hold off;
% ============================================================
end
Every time I run this script I receive an error stating 'Not enough input arguments. Error in plotData (line 19) plot(x, y, 'rx');'. This is a fairly ambiguous error message and I am not sure how to interpret what is wrong here. I don't see why I wouldn't have enough input arguments in this example as the function explicitly takes both x and y and uses each to plot data as defined by the function. Any help would be greatly appreciated.
I am using MATLAB version 9.6.0.1114505 (R2019a) Update 2
I was getting the same error on running 'plotData.m',
Please try running 'ex1.m' and not 'plotData.m'
I really need help in the histogram plot from a csv file format. When I searched in the internet for histogram it was suggested hist function. In the following example hist is working only for x or y but not both. My expected plot is shown in figure1 red plot. By matlab code I am getting plot as shown in figure2 blue plot.
close all
data = csvread('mc_10000_better.csv',4); % Read the data
y = data(:,1) ;
x = data(:,2) ;
plot(y,x)
xlabel('Samples')
ylabel('Current')
I am writing code in MATLAB for convolution and then deconvolution
But when i try to run/simulate, i get following error;
Error using deconv (line 19)
First coefficient of A must be non-zero.
Error in Untitled (line 10)
x1=deconv(y,h)
The code that i am using is as follow:
clc, clear all, close all
t=[0:0.1:36]
h=exp(-2*t).*heaviside(t-1)
x=heaviside(t)-heaviside(t-2)
y=conv(x,h)
plot(y)
xlabel('Time')
ylabel('Amplitude')
title('y(t)=x(t)*h(t)')
x1=deconv(y,h)
How can i get out of this error, as i have to find back input x,by using deconv command which takes two arguments(output y and impulse response h)
Im trying to calculate the area of randomly generated graph, which is created from randomly generated x and y values and drawn using polyfit.
clear
clc
for i=1:8
x(i)= round((12+5).*rand - 5,0)
y(i)= round((7+6).*rand -6,0)
end
p=polyfit(x,y,5);
x1=-5:0.1:12;
y1=polyval(p,x1);
plot(x,y,'o')
hold on
plot(x1,y1)
y2=(x1)*0-5
plot(x1,y2)
hold off
syms x
S1=int(x.*0-5,x,-2,7)
pp=polyint(p,x)
S2=polyval(pp,-2)-polyval(pp,7)
S=S1+S2
However, I am getting this weird error that doesnt make any sense to me.
Undefined function 'filter' for input arguments of type 'sym'.
Error in polyval (line 56)
y = filter(1,[1 -x],p);
Why doesnt it allow me to use polyval after using polyint ? Its still a polynomial..
In other words. How could I change the end of the code to calculate the definite integral of the newly formed polynomial, which is always different
I have one vector (newdata) consisting of 4100 lines and one column. To be exact, those elements are the counts of a spectrum. What I want is to reproduce the spectrum using MATLAB. That's why I created a new vector:
channels=[1:size(newdata,1)];
I tried to plot the spectrum (using channel in x axis and newdata as a weight) by typing:
hist(channels,newdata)
But I got an error
??? Error using ==> histc
Edges vector must be monotonically non-decreasing.
Error in ==> hist at 86
nn = histc(y,[-inf bins],1);
How can I draw the desired spectrum?
try plotting using the bar command
bar( channels, newData );