matlab-figure

Matlab legend colors don't match lines

末鹿安然 提交于 2019-12-13 17:11:38
问题 Not sure what is going wrong here. I created a minimal example below: clear steps = 1:6; labels = cell(length(steps),1); xvals = 1:10; fig = figure(1); ax = axes('parent',fig); hold on for ii=1:length(steps) s=steps(ii); yvals = zeros(length(xvals)) + ii; labels{ii} = ['gain = ' num2str(s)]; plot(ax,xvals,yvals); end legend(ax, labels); hold off And the result on my system is: With less lines it can even put colors in the legend that aren't even on the plot. What is happening?! 回答1:

Shade and calculate specific area

谁说我不能喝 提交于 2019-12-13 15:38:15
问题 I tried to change the code in a way so that only the first area is shaded grey. How can I set the horizontal line in a way that it only appears under the area I want to shade? Furthermore I want to calculate the area of ONE region. How do I achieve that? I know it is trapz but I am not sure how to set the boundaries. Thanks! x = 0:.01:4*pi; %// x data y = sin(x); %// y data level = 0.5; %// level plot(x, y) hold on area(x, max(y, level), level, 'EdgeColor', 'none', 'FaceColor', [.7 .7 .7])

Save Matlab workspace without saving or deleting figures

荒凉一梦 提交于 2019-12-13 13:55:47
问题 The documentation for the save command says that you should delete figures if you don't want to bog down the *.mat file. I save to a *.mat file periodically, and I re-use my figure after issuing clf . I would prefer not to have to delete it just to save a *.mat file, then open a new figure. Is there a way to do this? 回答1: You can either save the variables you want explicitly when calling save if you know all the variables you'd like to save. save('output.mat', 'variable1', 'variable2',

Saving MATLAB figures as PDF with quality 300 DPI, centered

北慕城南 提交于 2019-12-13 12:03:08
问题 I want to save a MATLAB figure as PDF, with quality 300 DPI, and centered. So far I managed to save it, but the image appears cropped. I changed the page type to A3 and kind of solves the problem, but I am looking for something more elegant. I am doing it from the GUI, but maybe from the command line is easier in MATLAB. Is there any package or script that makes this (fundamental task for publications and papers) a bit easier? 回答1: Try using the following command: print -painters -dpdf -r300

Which one of the following is an efficient code for this MATLAB?

删除回忆录丶 提交于 2019-12-13 11:24:25
问题 Arrange the 2 given images into one image with image1 (pedestrian) on the left and image2 (no-parking) on the right in one single image. Display the combined single image. Code 1 :- z = imread('NO_PARKING.jpg'); x = imread('PEDESTRIAN.jpg'); r = imresize(z,[500,500]); c = cat(2,x,r); imshow(c) Code 2:- [X1,map1]=imread('PEDESTRIAN.jpg'); [X2,map2]=imread('NO_PARKING.jpg'); subplot(1,2,1), imshow(X1,map1) subplot(1,2,2), imshow(X2,map2) Which of the above codes is correct? 回答1: The two codes

How to concatinate multiple graphs on the same x y axis in matlab? [duplicate]

混江龙づ霸主 提交于 2019-12-13 10:03:44
问题 This question already has answers here : Multiple plots coombine and concatenate in matlab [closed] (2 answers) Closed 2 years ago . I have for loop that plots multiple graphs, whereby each graph has own window. I would like to concatenate these graphs using only one graph and x y axis. Could someone give an example? 回答1: The following code plots a few points in a single graph. You can place anything you'd like to plot in this plot() function. x = [1,2,3,4]; y = [5,3,4,6]; figure; % Create a

Generate a 3D surface plot by fitting over many 2D plots with varying z value

ぃ、小莉子 提交于 2019-12-13 09:28:59
问题 I would like to achieve a 3D surface plot. My outputs are as follows. For a particular value of z, I get y for each value of x (x ranges like 0:0.1:1.4 ). Then I vary z and, for the same range of x, I get y values. The result can be visualised as 2D plots at discrete z values, consisting of the range of x and its corresponding y. Here is my original plot: I would like to create a 3D surface plot instead, like a blanket wrapped over the above 2D plots. 回答1: Here's an example for the two types

How to Get Dynamic Legend on Linear Graph in Loop?

谁都会走 提交于 2019-12-13 09:26:14
问题 Diff conditions: how to clear dynamic legends at the end of each iteration; how to remove fitted linear lines at the end of each iteration. I am trying to extend this answer of the thread Dynamic Legend (Updates in every recursion) to iterate legend on one graph. Proposal to cover dynamic legend on one linear graph close all; clear all; % Test data aSize=zeros(2,777); aSize=[[0, 0]' randi(3,2,777)]; % STDEV about 3 x=0:1:180; hFig=figure; index=1; while (index<=7); % origo left alone aSize(:,

How to convert grayscale image to rgb with full colors? [closed]

二次信任 提交于 2019-12-13 09:22:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm trying to convert a grayscale image to rgb image . I searched the net and found this code: rgbImage = repmat(grayImage,[1 1 3]); rgbImage = cat(3,grayImage,grayImage,grayImage); but what this does is only give the image in gray-scale with 3-D matrix. I want to have a way that i can convert it into true color

How to plot two functions on one graph?

馋奶兔 提交于 2019-12-13 09:09:17
问题 I've been given the homework to graph the function x^3 and 3^x in one graph. Does anyone could help me with this exercise please? 回答1: every time you call plot matlab will clean the canvas before drawing the new function, unless you are focused on a window where you called hold on , which will substantially tells Matlab to keep the old stuff and superimpose the new drawing. x = 0:0.001:10 y1 = x.^3; y2 = 3.^x; plot(x, y1); hold on; % without this one will delete y1 before drawing y2 plot(x,