matlab-figure

Plot several lines (looping through line styles in cell array) in Matlab

家住魔仙堡 提交于 2019-12-02 11:24:07
问题 I have written this loop to plot each line of results and I get the error message Error using plot. Invalid first data argument. So far it looks like this test=rand(5,6); xint=[1:1:6]; LineSpec = {'-y', '--m', ':c', '-r.', '-b', ':s'}; for ii=1:5, plot(xint,test(ii,:),LineSpec(ii),'linewidth',2); hold on; legend_str{ii} = num2str(ii); end If I use plot(xint,test(ii,:),'-y','linewidth',2) then it works. But how can I avoid the error when looping through line styles? 回答1: You should write: plot

Animating a ball in Matlab

一曲冷凌霜 提交于 2019-12-02 11:17:31
I have a ball with these two equations: x(t) = v0*cos(α)*t and y(t) = h + v0*sin(α)*t− 1/2 g t^2 , where t ∈ [0,t final] is the time variable, h is the height, v0 is the initial speed, α is the angle made by v0 with the horizontal, g = 9.8 m/s^2. The floor is at y(x) = 0. I need to draw a small animation of the ball moving on the plot. I now I should use for, plot, drawnow, but I don't know how to do it. Can you tell me how to obain this animation? First, here are some test variables to start with, including the acceleration due to gravity: g = 9.8; %// m/s^2 v0 = 2; %// m/s alpha = pi/6; %//

How to add a different title to LTIview?

半世苍凉 提交于 2019-12-02 11:11:40
I want to plot step response of a second order transfer function using LTIview in different conditions such as underdamped,critically damped condition etc. I want to plot them in the same matlab program so want to give my own title names such as 'underdamped' condition. But the following code for plot function doesn't work and the GUI gives the preinitialised names figure,ltiview('step',trf),title('underdmp') Or ltiview('step',trf),title('overdamped') How to solve this problem? And give the names according to my choice? In order to costomize the title property of a plot in a standard toolbox

MATLAB how to automatically read a number of files

爱⌒轻易说出口 提交于 2019-12-02 10:59:45
I would like to plot a number of 3D graphs from different data files. For example I am using fid = fopen('SS 1.dat','r'); to read the first file and then plot a graph. How to set the program to change the name to 'SS 2.dat' automatically? Also for the tenth file the name becomes 'SS 10.dat' which has one space less (i.e.only two space between SS and 10) then the first to ninth files. How to set the program to adjust for that? Thank you. The following code displays a lazy way to print the names from 1 to 999 that you mentioned: for ii=1:999 ns = numel(num2str(ii)); switch ns case 1 fname = ['ss

Pick a specific level in the contour plot on matlab

痴心易碎 提交于 2019-12-02 10:54:07
I have this plot that I generated as a test of figuring out how contour plots work on matlab in general. I'm trying to figure out if there is a way I can plot just one of the lines but not necessarily the first line. They way Matlab explains it is if you do: contour(X,Y,Z,1); it will plot one of the lines but it's always the first one, but for my particular case I want the 3rd or 4th one. Is there a way to do that in Matlab? contour(Z,N) and contour(X,Y,Z,N) draw N contour lines, choosing the levels automatically. This is not what you want! contour(Z,V) and contour(X,Y,Z,V) draw a contour line

Adding a legend when using imagesc, including white for NaN

爷,独闯天下 提交于 2019-12-02 10:11:03
问题 I have a 35x43 matrix of data with vales ranging from 1-6 and lots of NaNs. I want to NaNs to be white, and the numbers to each be a different colour. I need a legend with the 6 different colour and labels on it. I can achieve most of this with the following code, however the colours in the legend do not match the colours in the figure. See code below figure(6) subplot(1,2,1) imagesc(lut) title('Highest Weighted Predictor variable for each Pixel') ylabel('Longitude') xlabel('Latitude') caxis(

ColorOrder setting has no effect

99封情书 提交于 2019-12-02 09:57:34
问题 I am using Matlab version R2014a and I am trying to have plot look like the Simulink scope. My code works as it should except, the ColorOrder setting is not reflected in the output. Right after setting ColorOrder I retrieved it with current_co=get(gca, 'ColorOrder'); and it gives back the value that I have set. However in the diagram the default colors are used. Why is this? How can it be fixed? my_co=[1.0 1.0 0.0; 1.0 0.0 1.0; 0.0 1.0 1.0; 1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0; 1.0 1.0 1.0];

How to create movies on each generation of a for loop in Matlab plot

我是研究僧i 提交于 2019-12-02 09:50:20
I want to plot the sphere function as a surface or a contour plot, and the position and fitness value of the best individual which are evaluated by a sphere function of data generated from a Gaussian distribution superimposed with it. The plot will change in each generation so i get a movie. Also, on another figure, i want to plot the contour of the sphere function superimposed with the entire population generated from Gaussian distribution, with the retained fit individuals colored in red. This from generation to generation should give another movie. This is basically an implementation of

How to show categorical data on x-axis when using bar function?

放肆的年华 提交于 2019-12-02 09:20:38
问题 I am trying to simulate a code which is on the official MATLAB website, but I cannot get the same output. This is the code: c = categorical({'apples','oranges','pears'}); prices = [1.23 0.99 2.3]; bar(c,prices) This is the correct output which is on the MATLAB website: This is the output that I get in my MATLAB: The c array, which is apple , orange and pears is not showing in my MATLAB output. Why don't I get the same output? My MATLAB version is R2016a. 回答1: You can try the following

XTickLabel with variable intervals at barplot

我与影子孤独终老i 提交于 2019-12-02 09:18:41
I have a barplot where the bars are located at the following x-coordinates: 1,2,3,4,5,6,7,8,9,10,12,14,16,18,20,22,24,26,28,30,35,40,45,50,55,60,70,80,90 I want to show these values at the XTickLabel , however when I use figure(1); Vector = [1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 22 24 26 28 30 35 40 45 50 60 70 80 90] bar(Vector,Vector); xticklabels(Vector); I get the following output, but I want that my XTickLabel to look like Vector at the corresponding values: As you can see the XTickLabel only goes to 12 and some bars are not labeled. I tried to use set(gca,'Xtick',1:1:Vector(length(Vector))