matlab-figure

Using getframe in Matlab on Windows

假如想象 提交于 2019-12-02 03:44:18
I used the code which I asked about here but added in the final loop the ani(ii)=getframe; and after the loop movie2avi(ani, 'orbeeit.avi', 'compression', 'None'); . instead of proper avi I get a frozen smashed avi (length 10 sec) which its only frame is this one . What am I doing wrong? This problem is probably caused by Windows Vista (and newer) in conjunction with certain graphics drivers as described in this bug report . You can change the renderer after you created the figure: set(gcf,'Renderer','zbuffer'); Or opengl('software'); 来源: https://stackoverflow.com/questions/16885207/using

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

送分小仙女□ 提交于 2019-12-02 03:38:59
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? You should write: plot(xint,test(ii,:),... LineSpec{ii},... 'linewidth',2); LineSpec is a cell array, so LineSpec(ii) returns a

How to halt matlab plot3 scale

允我心安 提交于 2019-12-02 03:30:57
I want to plot pendulum (which changes position) using plot3 function. Unfortunately, when my dot changes position in loop and is being plotted again, the scale of 3d plot is changing too, so the x axis depending on position changes (depending on position of the dot it can be from -1 to -1.5 or from -1 to -3) and y changes also. Only z states the same. The result is that the dot jumps on graph and does not create impression of pendulum. This is how I plot: plot3(0,0,0); daspect([1,1,1]); axis([-10, 10, -10, 10]); scatter3(x(i)-rs, y(i)-rs, 0); I tried to deal with the problem using: gca or set

How to label x-axis with dates?

◇◆丶佛笑我妖孽 提交于 2019-12-02 03:22:33
问题 I cant seem to figure out how to plot dates in Matlab that aren't in numerical order. The dates I need are from January 22nd to Feburary 1st, but when I put it in Matlab it goes in numerical order starting from the 1st. So I was wondering how to get it so that it goes in order of the list I have. Here is the code I've made: date = [22 23 24 25 26 27 28 29 30 31 1 2 3 4]; in_bed = [3 8 26 76 225 298 258 233 189 128 68 29 14 4]; convalescent = [0 0 0 0 9 17 105 162 176 166 150 85 47 20]; plot

How to change the font size of a plot's title and axis labels and save it?

a 夏天 提交于 2019-12-02 03:02:18
Every time I save a plot picture as jpg or png, font size of title and axis label is changed back to default automatically. My code is like this: figure plot(x, f(x)) title('the smallest n = 1', 'FontSize', 24); xlabel('x', 'FontSize', 24); ylabel('x''', 'FontSize', 24); After saving the picture, those font sizes become small again. Anyone knows why? Because it just applies for the current figure. If you want to set the same font size for the whole session, use: set(0,'defaultAxesFontSize', 12); If you want that permanently, put it in your start-up file. By the way, as you can see here you can

Adding a legend when using imagesc, including white for NaN

给你一囗甜甜゛ 提交于 2019-12-02 03:00:16
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([0, 7]) myColorMap = jet(7); myColorMap(1,:) = 1; colormap(myColorMap); M = jet(7); % Notice the 3,

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

China☆狼群 提交于 2019-12-02 02:46:17
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. You can try the following workaround (as mentioned here ): prices = [1.23 0.99 2.3]; bar(prices) set(gca,'xticklabel',{'apples','oranges',

What does the index refer to when selecting a pixel on an image in Matlab?

こ雲淡風輕ζ 提交于 2019-12-02 02:42:21
When looking at a single pixel of an image in Matlab, what does this index refer to? X/Y refer to the coordinates of the pixel, and RGB refers to the color, but any ideas on what the index is? To clarify, when I am viewing a figure in Matlab and use the data cursor to select a point, the three lines shown are: X: ### Y: ### Index: ### RGB: ###, ###, ### I am trying to "average" several dicom images together, and it appears that the numbers that are added and being manipulated is this index value, but I'm not sure what it refers to. For example, here is an image that I might be reading: %loads

How to properly display TeX strings in axes' datatips? (MATLAB hg2)

谁都会走 提交于 2019-12-02 02:38:49
I have recently tried to run an old piece of code (written on hg1) on a new version of MATLAB (2015a) that has hg2. I used to be able to do the following (according to the " gnovice - Amro " method): function output_txt = customDatatip(~,event_obj) % Display the position of the data cursor % obj Currently not used (empty) % event_obj Handle to event object % output_txt Data cursor text string (string or cell array of strings). hFig = ancestor(event_obj.Target,'figure'); %// I don't trust gcf ;) pos = get(event_obj,'Position'); output_txt = {['\lambda: ',num2str(pos(1)*1000,4) 'nm'],... ['T(

How can I control which monitor plots are displayed on?

心不动则不痛 提交于 2019-12-02 02:26:38
问题 I have a 3 monitor Gentoo Linux system running MATLAB. MATLAB runs on the center monitor. I need MATLAB to generate plots on the left monitor but it always plots on the right monitor. I believe this is at least partially caused by the non-standard way I have my monitors arranged physically - essentially 2,3,1: >> get(0,'MonitorPositions') ans = 1 1 1920 1080 -3839 1 1920 1080 -1919 1 1920 1080 Is there a way I can control this as a default within MATLAB? 回答1: You can set the default figure