Plotting the relationship between four variables in MATLAB [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am struggling with something that should not be too hard; I have three variables (x,y,z) and an outcome (e), and I know the relationship between them. Let's for the sake of it assume that the relationship is as follows:
e = x + y.^2 + (4/z)
Now, what I want to do is create a plot in MATLAB that shows me this function, with the three variables on the respective axes, and the color reflecting the outcome (e). I know it probably has something to do with meshgrid and surf, but from the way I see it, those can only plot three variables total, and not four, as in my case.
Thanks in advance for your help,

I tried out using isonormals() and it gave a useful plot:
The red surface corresponds to e = 0, whereas blue and green surfaces show e = 5 and e = -5 respectively.
Here is the code:
clear;
[x, y, z] = meshgrid(-30:0.5:30, -10:0.5:10, -1:0.01:1);
e = x + y.^2 + 4./z;
e1 = 0; e2 = 5; e3 = -5;
e_val = [0, 5, -5];
c_val = ['r', 'b', 'g'];
for i=1:length(e_val)
p = patch(isosurface(x,y,z,e,e_val(i)),'FaceColor',c_val(i),'EdgeColor','none');
isonormals(x,y,z,e,p);
hold on;
end
hold off;
xlabel('X');ylabel('Y');zlabel('Z');
view(3); axis tight;
camlight;
lighting gouraud;

Related

I need help to solve my matlab problem in plot surface [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Please can anyone help me to solve my Matlab problem. I will share the question and it need to be solved in Matlab. Thanks in advance for your help.
Using meshgrid() to Plot Surface
This method uses two vectors to set the axes. After creating the axes the grid over coordinates to plot over (domain) is created using the meshgrid(). The meshgrid() function will take two vectors that describe the axes. After creating this grid of coordinates the function k can be evaluated for all the points on the grid-pair.
For 6 ≤ n ≤ 12 (ten values) and 0.001 ≤ p ≤ 0.009 (five values):
Here you can see the top row of images showing the vectors used to create the axes. The second row of images shows the grid formation created using meshgrid(). You can see by taking one cell/value from n and one cell value from p a coordinate pair is formed → (n,p). For example, one coordinate point can be (n,p) → (6,0.0030).
For 6 ≤ n ≤ 12 (ten values) and 0.01 ≤ p ≤ 0.1 (ten values):
Number_Of_P_Ticks = 5;
P_Axis = linspace(0.001,0.009,Number_Of_P_Ticks);
Number_Of_N_Ticks = 10;
N_Axis = linspace(6,12,Number_Of_N_Ticks);
[p,n] = meshgrid(P_Axis,N_Axis);
k = -p.*n + sqrt((p.*n).^2 + (2.*p.*n));
subplot(1,2,1); surf(p,n,k,'FaceAlpha',0.9);
title("10 Values of p and 5 Values of n");
xlabel("p"); ylabel("n");
Number_Of_P_Ticks = 10;
P_Axis = linspace(0.01,0.1,Number_Of_P_Ticks);
[p,n] = meshgrid(P_Axis,N_Axis);
k = -p.*n + sqrt((p.*n).^2 + (2.*p.*n));
subplot(1,2,2); surf(p,n,k,'FaceAlpha',0.9);
title("10 Values of p and 10 Values of n");
xlabel("p"); ylabel("n");
Ran using MATLAB R2019b

How can I use a linear filter from the frequency domain to remove noise in an image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So I have worked with linear filters from the Spatial domain but in the Frequency domain I have troubles understanding how to implement any filter in Matlab. Could anybody explain me how to do that?
I want to see how I can use a filter from the frequency domain to remove noise from an image.
See This Example for Moon Landing Image.
%=====================
clc;
clear all;
close all;
%=====================
im = imread('moonlanding.png');
%=====================
FT = fft2(double(im));
%finding spectrum
FTS = fftshift(FT);
FTSG= log(FTS+1);
figure;
imshow(abs(FTSG),[]);
%imtool(abs(FTS),[]);
[m,n] = size(im);
%====================
t = 0:pi/10:2*pi;
% point around which we filter image
xc=(m+150)/2;
yc=(n-150)/2;
%======================
figure;
subplot(221)
imshow(im);
%======================
for k = 1:3
%Radium of circular region of interest(for BRF)
%r=200;
%r1 = 40;
r = 200;
r1 = 50*k;
%------------------------
xcc = r*cos(t)+xc;
ycc = r*sin(t)+yc;
xcc1 = r1*cos(t)+xc;
ycc1 = r1*sin(t)+yc;
%------------------------
mask = poly2mask(double(xcc),double(ycc), m,n);
%generating mask for filtering
mask1 = poly2mask(double(xcc1),double(ycc1), m,n);
mask(mask1)=0;
FT2=FTS;
FT2(mask)=0;%cropping area or bandreject filtering
%========================
% Display Results
%imtool(abs(FT2),[]);
%subplot(211)
%imshow(abs(FT2),[]);
output = ifft2(ifftshift(FT2));
subplot(2,2,(k+1));
%imtool(output,[]);
imshow(abs(output),[]);
end

getting a plot of 3 competing species [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to make a code for a model of competing three species to get plots ( polt 3d z against x,y and 2d plot x,y,z against time )
My model is
x'=(r1-a1x-b1y-c1z)x
y'=(r2-a2x-b2y-c2z)y
z'=(r3-a3x-b3y-c3z)z
where
r1=1.5; r2=2.65; r3=3.45;
a1=0.1; b1=0.3; c1=0.01; b2=0.2;
a2=0.3; c2=0.2; c3=0.2; a3=0.01; b3=0.1.
any help to do this code would be appreciated.
Solve the problem:
% Define diff. equations, time span and initial conditions, e.g.
tspan = [0 20];
y0 = [0.2 0.2 0.2];
r1=1.5; r2=2.65; r3=3.45;
a1=0.1; a2=0.3; a3=0.01;
b1=0.3; b2=0.2; b3=0.1;
c1=0.01; c2=0.2; c3=0.2;
dy = #(t,y) [
(r1-a1*y(1)-b1*y(2)-c1*y(3))*y(1);
(r2-a2*y(1)-b2*y(2)-c2*y(3))*y(2);
(r3-a3*y(1)-b3*y(2)-c3*y(3))*y(3)];
% Solve differential equations
[t,y] = ode45(dy, tspan, y0);
Now just plot the results:
% Plot all species against time
figure(1)
plot(t,y)
% 3D plot of z against xy
figure(2)
plot3(y(:,1), y(:,2), y(:,3))
grid on
xlabel('x')
ylabel('y')
zlabel('z')

Matlab (How to fit multiple data sets ) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Suppose I have for vectors x1, y1, x2, y2, and I would like to plot this data (x1,y1) and (x2,y2) with different colors. The dimesions of vector x1,y1 are not the same with x2,y2.
Than I would like also to fit all this data together, with the same polynomial fit, degree 1.
Can someone help me to do it?
You can plot the vectors simply using plot:
plot(x1, y1, 'r.', x2, y2, 'b.')
where the 'r.' specifies that this first pair should be plotted in red dots, and the 'b.' specifies that the second pair should be plotted in blue dots. You can find a more complete list of color/marker options in the help documentation for plot.
To fit a polynomial to (x,y) data, you can use polyfit:
poly_coeffs = polyfit( x, y, poly_degree )
If you want to fit the same polynomial to both sets of data, you should concatenate your vectors into a single vector, e.g. (in the case of row vectors):
x = [x1, x2]
y = [y1, y2]
poly_coeffs = polyfit( x, y, poly_degree )
If you have column vectors, you would use x = [x1; x2] (note the semicolon instead of the comma) to concatenate them vertically.
And now if you wanted to plot the polynomial fit on top of the original data, you can add it on to the list of arguments to plot:
curve_x = linspace( min(x), max(x), 100 );
curve_y = polyval( poly_coeffs, curve_x );
plot(x1,y1,'r.', x2,y2,'b.', curve_x,curve_y,'k-');

How to plot probability density function? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
i want to plot probability density function for about 7500 data that shows peak ground acceleretion(PGA).what is the MATLAB code for this?thanks.
I think you want to estimate the probability densiry function from your data. That's a histogram, and for that you use the hist function:
data = randn(1,7500); %// example data
n = 21; %// number of bins
[y, x] = hist(data, n);
y = y/(x(2)-x(1))/numel(data); %// normalize so that total area is 1
plot(x, y)
%// To check that area is approximately 1, compute the integral: trapz(x, y)
If you happen to know your distribution (for example Gaussian) you can do this:
data = randn(1,7500);
[mu sigma] = normfit(data);
X = mu - 10 : .1 : mu + 10;
Y = normpdf(X,mu,sigma);
plot(X,Y);
And you could get this,
However if your data isn't Gaussian, you can use other fitting functions.