I am having an issue when trying to plot these two timeseries against each other:
subplot(2,2,3),plot(wrm,Te);title('Speed-Torque curve');
xlabel('wrm [rad/s]');ylabel('Te[Nm]')
axis([-5 10 20 200]);
grid;
It comes up with the error of
Error using plot
A numeric or double convertible argument is expected
Error in timeseries/plot (line 163)
p = plot(ax,Time,Data,varargin{:});
I have tried changing the "to workspace" variables in simulink from 1x1 double timeseries to arrays and that seems to allow me to plot, but the plot for just Te become incorrect.
All other plots I create, I am unable to follow the format of plot(time,yvariable) as it gives the same error so I have been just using plot(yvariable) which has worked up until now.
Any help would be appreciated. Thanks!
From your question I don't understand exactly what you are trying to do. If you are trying to plot the data members of the two timeseries objects against each other, use
plot(wrm.Data, Te.Data);
If you are plotting the data members, you of course need to make sure these vectors are the same length. If they are not, you could use something like
Te2 = resample(Te2, wrm.Time);
If you want to plot both against time instead, use
plot(wrm); hold on; plot(Te);
Or, as I like to do:
wrm.plot(); hold on; Te.plot();
Related
I'm trying to get a better grip of how it all flows and I'm trying to plot myself a Dirac delta plot which is supposed to be an effect of putting a Zadoff-Chu through cyclic autocorrelation.
This is the formula that I'm adhering to:
circcorr_ab = ifft(fft(a).*conj(fft(b)))
And I'm expecting something resembling this (zeroes on Y besides X = 0)
Instead I'm getting this:
Obviously I'm getting very small values on Y axis, zeros for all intents and purposes, and an expected 839 on the X axis. It looks like I need to flip the plot and normalize the values but I can't come up with a functioning solution.
Help appreciated.
You need to plot the absolute value of the result. Try
plot(abs(circcorr_ab))
I have used TSNE in MATLAB for dimensionality reduction of a large data. I have been able to generate the Scatter Plot for TSNE in 2 dimensions which shows the labels of the cluster in different colors for each label, but, I am unable to do so in 3D. Referring to https://uk.mathworks.com/help/stats/tsne.html, I used the following syntax:-
Where, merged_data_all is a 21392x1974 table with the last column named FunctionalGroup containing different labels (similar to the Fisheriris species labels in the Mathworks example on tsne). Y2 is the 3 dimensional variable which I have been successfully able to generate of dimensions 21392 x 3 double.
figure
v = double(categorical(merged_data_all.FunctionalGroup));
c = full(sparse(1:numel(v),v,ones(size(v)),numel(v),3));
scatter3(Y2(:,1),Y2(:,2),Y2(:,3),15,c,'filled')
title('3-D Embedding')
view(-50,8)
When I use this code, I get the error "Error using sparse- Index exceeds array bounds". I even tried to use a modified version of the code and doing something like this
scatter3(Y(:,1), Y(:,2),Y(:,3),merged_data_all.FunctionalGroup)
In case of this, I get the error "Error using scatter3- Input arguments must be numeric, datetime or categorical". I am quite confused as to how I can plot a 3d scatter plot, with 14 different colors (for the 14 types of different labels I have in my FunctionalGroup column of merged_data_all). Any help in this regard would be highly appreciated. Thanks
This could be simple question. However, I tried/searched extensively before posting this question.
I have struct called particle and it contains a variable particle(i).center, which is actually a coordinate variable. I am trying to plot those coordinates using plot3 something like,
hold on;
for i=1:np
plot3(particle(i).center, 'r+')
end
I receive an error message saying the following:
Error using plot3
Not enough input arguments.
I realize the error is that the variable is passed as 3x1 array instead of 3 comma separated variables. Can anyone suggest, how to plot 3D coordinates as in above case?
Your particle structure needs to have
particle(i).center.x
particle(i).center.y
particle(i).center.z
and then plot3(particle(i).center.x,particle(i).center.y,particle(i).center.z,...)
I am trying to plot 3 vectors onto matlab GUI in a serial object's callback.
I want to plot this on axes handle but the problem is it only plot last vector;
plot(handles.axes1,sensor1,'r');
plot(handles.axes1,sensor2,'b');
plot(handles.axes1,sensor3,'g');
I searched on internet and find that this issue can be solved with hold on and hold of feature so I tried this
plot(handles.axes1,sensor1,'r');
hold on ;
plot(handles.axes1,sensor2,'b');
plot(handles.axes1,sensor3,'g');
hold off;
but in this case a new figure is opened(dont know why) and again only the last plot is drawn.
I am stucked. If any one have idea of what would be the issue?
Thanks
I'm not sure why your first try using "hold" didn't work. Seems like it should have.
But in any case, you can get the desired behavior in a single command:
plot(handles.axes1,length(sensor1),sensor1,'r',...
length(sensor2),sensor2,'b',...
length(sensor3),sensor3,'g');
This specifies both an X = length(sensor_) and a Y = sensor_ to the plot command. When you only give plot a Y input, it assumes an X of length(Y). But you can't combine multiple traces in a single plot command by giving only the Y input for each, because it will try to treat the inputs as X,Y pairs.
As the vectors are the same length we can simply combine them as the columns of a matrix and then plot the matrix
plot(handles.axes1,[sensor1',sensor2',sensor3'])
However these will have the default colour order. Without specifying x values setting colors within the plot command is tricky. However (luckily) the default order starts:
blue,green,red...
so swapping the column order will plot the lines with the colours requested
plot(handles.axes1,[sensor2',sensor3',sensor1'])
(this assumes the vectors are rows, if they are columns don't transpose them)
I'm just getting started with matlab and I'm trying to plot some graph with it.
The problem is I don't know how to get the average data out of 10 plot().
Can anyone guide me for it? Thank you :)
Assuming you don't have access to the original data you used for doing the plots:
plot_data = get(get(gca,'Children'),'YData'); % cell array of all "y" data of plots
average = mean(cell2mat(plot_data));
In order for this to work, you have to use this code right after doing the plots, that is, without plotting to any other figure (gca is a handle to the current axes).
Assume your data is stored row-wise in a m x n matrix A, with n columns corresponding to different values of the continuous error, and m rows corresponding to different curves. Then to inspect the mean over the curves just use
Amean = mean(A,1);
plot(Amean)
Please take a look at this link: it solve my problem getting the average plot.
https://www.mathworks.com/matlabcentral/fileexchange/27134-plot-average-line
After downloading the files just put those script on your working folder and add this line to your script.
plotAverage(gca,[],'userobustmean',0)