matlab-figure

Multiple colors in the same line

…衆ロ難τιáo~ 提交于 2019-12-17 17:13:29
问题 I would like to plot a sine curve in Matlab. But I want it blue for the positive values and red for the negative values. The following code just makes everything red... x = []; y = []; for i = -180 : 180 x = [x i]; y = [y sin(i*pi/180)]; end p = plot(x, y) set(p, 'Color', 'red') 回答1: Plot 2 lines with different colours, and NaN values at the positive/negative regions % Let's vectorise your code for efficiency too! x = -pi:0.01:pi; % Linearly spaced x between -pi and pi y = sin(x); % Compute

Dynamic Legend (Updates in every recursion)

倖福魔咒の 提交于 2019-12-17 15:41:58
问题 I got a for i=1:15 . Inside I generate a variable d=1:0.01:10 , which is the x'x axis and based on this, I create a continuous function F(d) which has 2 unique variables pitch and yaw. I then plot this using different colors in every recursion using cmap = hsv(15); . So then it is: d=1:0.01:10; cmap = hsv(15); for i=1:15 pitch = unidrnd(10); yaw = unidrnd(10); for j=1:length(d) F(j) = d(j)*3*pitch*yaw; %// some long calculation here end p1 = plot(d,F,'Linewidth', 1.0); title ('blah blah') set

How to insert two X axis in a Matlab a plot

萝らか妹 提交于 2019-12-17 10:59:58
问题 I would like create a Matlab figure with a double X axis (m/s and km/h) with the same plot. I have found plotyy and - in Matlab reposity - plotyyy, but I am looking for: A double X axis. Together below the plot. My code is very simple: stem(M(:, 1) .* 3.6, M(:, 3)); grid on xlabel('Speed (km/h)'); ylabel('Samples'); M(:, 1) is the speed (in m/s), and M(:, 3) is the data. I would like only a second line, in the bottom, with the speeds in m/s. 回答1: You can do something like the following. In

How to set x and y values when using bar3 in Matlab?

微笑、不失礼 提交于 2019-12-17 09:59:28
问题 Quick version How can I control the x- and y-values for a 3-d bar plot in Matlab? Details Say we have an 10 x 20 data matrix and we plot it using bar3 , and we want to set the x- and y-values. For instance: foodat = rand(10,20); xVals = [5:14]; yVals = [-3:16]; bar3(xVals, foodat); xlabel('x'); ylabel('y'); Is there a way to feed it the yVals as well? Otherwise the y axes always defaults to [1:N]. Note I don't just want to change the labels using XTickLabel and YTickLabel . I need to change

Plotting data on time (date) axis

北慕城南 提交于 2019-12-17 07:49:48
问题 I have data like this: 22.10.1980. 100 25.10.1980. 120 26.10.1980. 12 (only much more of it, and for each date, several independent measurements on the right). Now, this is probably trivial, but I've never done anything like it in MATLAB, and am having problems finding similar examples online. I need to plot the data on a time/showing dates axis (x axis), with all dates inside (so, 23. and 24. as well ... for which I don't have measurements). How can I get dates to show up on a plot axis? 回答1

How to pass surface map output of Matlab warp to export_fig?

人盡茶涼 提交于 2019-12-16 18:05:06
问题 Warp object is in polar coordinates which I cannot assign with axes so I cannot pass the surface object directly to export_fig . Code which generates the image but I cannot catch it for export_fig as shown below because no handle for it clear all; close all; clc; img=imread('peppers.png'); % http://stackoverflow.com/a/7586650/54964 [h,w,~] = size(img); s = min(h,w)/2; [rho,theta] = meshgrid(linspace(0,s-1,s), linspace(0,2*pi,s)); [x,y] = pol2cart(theta, rho); z = zeros(size(x)); figure; h

matlab: difference between KeyPressFcn and WindowKeyPressFcn

♀尐吖头ヾ 提交于 2019-12-14 03:46:04
问题 The Matlab documentation definition for KeyPressFcn is a "callback function invoked by a key press that occurs while the figure window has focus." Similarly, the definition for WindowKeyPressFcn is a "callback function invoked by a key press that occurs while either the figure window or any of its children has focus." As far as I understand, the children of figures are entities like axes, plot objects, and annotation objects. If one of these children has focus, then its parent figure

DFT of time domain for step function

北慕城南 提交于 2019-12-14 03:23:05
问题 I have been working on DFT in Matlab recently, here is my code in Matlab. which part of my code has problem, my sampling is wrong??? I'll be grateful if you answer my question: dt = 0.01; %sampling time interval Fs = 1/dt; %sampling rate t = 0:dt:45; %Time vector t0 = 5; %duration of applied stress N = length(t); %number of sample points y_timedomain = heaviside(t)-heaviside(t-t0); %the step function figure (1) plot(y_timedomain) axis([-100,1000,-0.2,1.2]); y_freqDomain=abs(fft(y_timedomain))

How modify some x-axis values in a .fig file in MATLAB?

折月煮酒 提交于 2019-12-13 18:16:57
问题 I have a .fig file that i want to modify just 2 values in x-axis. How is it possible when i do not have the source code of plotting? There is just a .fig file. 回答1: Pulling the data out with get(gca,...) is probably the most direct solution. However, there is some other obscure but useful MATLAB functionality worth mentioning. The first is the ability of MATLAB to generate M-files from figures, which can be used to recreate and modify a figure programmatically. Just click the following menu

How to detect a portion of an image based upon the matrix values?

耗尽温柔 提交于 2019-12-13 17:56:24
问题 I have a simple pcolor plot in Matlab (Version R 2016b) which I have uploaded as shown in the image below. I need to get only the blue sloped line which extends from the middle of the leftmost corner to the rightmost corner without hard-coding the matrix values. For instance : One can see that the desired slope line has values somewhere approximately between 20 to 45 from the pcolor plot. (From a rough guess just by looking at the graph) I'm applying the following code on the matrix named