Question

Please I need help with MATLAB .. PLease help me . Thankyou Write Matlab code to...

Please I need help with MATLAB .. PLease help me . Thankyou

Write Matlab code to plot a 2D sinc function over a 2D cartesian grid where x ranges from 100 to 355 and y ranges from 0 to 255 and the sinc is centered at somewhere not midway in the grid. First plot the grid, and then plot the function on the grid (both as grayscale and as a surface plot). Comment the code well, generate the figures and show your code in your report along with the figures. Please it should be a a MATLAB base-script.

The base script is the script that when executed, calls the functions written for each part of the assignment in sequence and produces all the figures in the assignment (named Figure_Question1_1.png, Figure_Question1_2.png etc.). Program MATLAB to also save the images as jpg/png files directly from MATLAB print(gcf,'-dpng',[savefilename '.png']); into a subfolder. Please make sure that the input figures are read in with reference to the location of the base script automatically and these inputs can be hardcoded in the base-script but not inside functions that you write. The particular functions you write should be generic and able to accept any inputs, so they can be called repeatedly from the base-script and passed the necessary information/images.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

meshgrid

2-D and 3-D grids

collapse all in page

Syntax

[X,Y] = meshgrid(x,y)

[X,Y] = meshgrid(x)

[X,Y,Z] = meshgrid(x,y,z)

[X,Y,Z] = meshgrid(x)

Description

example

[X,Y] = meshgrid(x,y) returns 2-D grid coordinates based on the coordinates contained in vectors x and y. X is a matrix where each row is a copy of x, and Y is a matrix where each column is a copy of y. The grid represented by the coordinates X and Y has length(y) rows and length(x) columns.

example

[X,Y] = meshgrid(x) is the same as [X,Y] = meshgrid(x,x), returning square grid coordinates with grid size length(x)-by-length(x).

example

[X,Y,Z] = meshgrid(x,y,z) returns 3-D grid coordinates defined by the vectors x, y, and z. The grid represented by X, Y, and Z has size length(y)-by-length(x)-by-length(z).

example

[X,Y,Z] = meshgrid(x) is the same as [X,Y,Z] = meshgrid(x,x,x), returning 3-D grid coordinates with grid size length(x)-by-length(x)-by-length(x).

Examples

collapse all

2-D Grid

Try This Example

View MATLAB Command

Create 2-D grid coordinates with x-coordinates defined by the vector x and y-coordinates defined by the vector y.

x = 1:3;
y = 1:5;
[X,Y] = meshgrid(x,y)
X = 5×3

     1     2     3
     1     2     3
     1     2     3
     1     2     3
     1     2     3

Y = 5×3

     1     1     1
     2     2     2
     3     3     3
     4     4     4
     5     5     5

Evaluate the expression x2+y2 over the 2-D grid.

X.^2 + Y.^2
ans = 5×3

     2     5    10
     5     8    13
    10    13    18
    17    20    25
    26    29    34

Plot Surface

Try This Example

View MATLAB Command

Create a 2-D grid with uniformly spaced x-coordinates and y-coordinates in the interval [-2,2].

x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x);

Evaluate and plot the function f(x,y)=xe−x2−y2 over the 2-D grid.

F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F)

Starting in R2016b, it is not always necessary to create the grid before operating over it. For example, computing the expression xe−x2−y2 implicitly expands the vectors x and y. For more information on implicit expansion, see Array vs. Matrix Operations.

surf(x,y,x.*exp(-x.^2-(y').^2))

3-D Grid

Try This Example

View MATLAB Command

Create 3-D grid coordinates from x-, y-, and z-coordinates defined in the interval [0,6], and evaluate the expression x2+y2+z2.

x = 0:2:6;
y = 0:1:6;
z = 0:3:6;
[X,Y,Z] = meshgrid(x,y,z);
F = X.^2 + Y.^2 + Z.^2;

Determine the size of the grid. The three coordinate vectors have different lengths, forming a rectangular box of grid points.

gridsize = size(F)
gridsize = 1×3

     7     4     3

Use the single-input syntax to generate a uniformly spaced 3-D grid based on the coordinates defined in x. The new grid forms a cube of grid points.

[X,Y,Z] = meshgrid(x);
G = X.^2 + Y.^2 + Z.^2;
gridsize = size(G)
gridsize = 1×3

     4     4     4

Input Arguments

collapse all

x — x-coordinates of points
vector

x-coordinates of points, specified as a vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

y — y-coordinates of points
vector

y-coordinates of points, specified as a vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

z — z-coordinates of points
vector

z-coordinates of points, specified as a vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

X — x-coordinates over grid
2-D or 3-D array

x-coordinates over a grid, returned as a 2-D (two inputs) or 3-D array (three inputs).

Y — y-coordinates over grid
2-D or 3-D array

y-coordinates over a grid, returned as a 2-D (two inputs) or 3-D array (three inputs).

Z — z-coordinates over grid
3-D array

z-coordinates over a grid, returned as a 3-D array

Add a comment
Know the answer?
Add Answer to:
Please I need help with MATLAB .. PLease help me . Thankyou Write Matlab code to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Image processing Matlab problem. Could you please help me to write a Matlab code to read...

    Image processing Matlab problem. Could you please help me to write a Matlab code to read images, equalize contrasts, covert images to grayscale and binary, then display on same windows. Then perform SOBEL and CANNY edge detection on images. Final make MATLAB to count the number of circles in images (circles and red circles) And how can we distinguish circles by color? and how to count number of red, green and blue circles separately for example.

  • please write code in matlab thankyou (10 points) Plot the function f(x) = (3cos-sinx)e-02x for-4 appropriate...

    please write code in matlab thankyou (10 points) Plot the function f(x) = (3cos-sinx)e-02x for-4 appropriate plot title and label the axes. After completing this step, you should obtain a plot in the Figure Window similar to the sample plot shown below: 2. 9. Add 0.2x 2- 0- -2 -8 -2 2 6 10

  • the picture above is the one you are supposed to use for the MATlab code please...

    the picture above is the one you are supposed to use for the MATlab code please help Problems. Grayscale images are composed of a 2D matrix of light intensities from O (Black) to 255 (White). In this lab you will be using grayscale images and do 2D-array operations along with loops and iflelse branches. 1. We can regard 2D grayscale images as 2D arrays. Now load the provided image of scientists at the Solvay Conference in 1927 using the imread)...

  • Need help with matlab code. If writing code out please make it where i can understand...

    Need help with matlab code. If writing code out please make it where i can understand and read it. I would prefer to see it in matlab form. Thanks Consider the RC Circuit shown below. Assume the excitation is a 10 kHz sine wave with amplitude of 1 volt. Derive expressions for the voltages across the resistor and the capacitor as time functions. Plot the voltages across the resistor and the capacitor over two periods using MATLAB and a reasonable...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks.please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me...

  • Can somebody help me with my matlab code? I am plotting the POWER SPECTRAL DENSITY OF...

    Can somebody help me with my matlab code? I am plotting the POWER SPECTRAL DENSITY OF Manchester, Polar, UNIPOLAR, and BIPOLAR. It wont run. The error I am getting is "incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform element wise multiplication, use '.*'. " clc; clear all; %Declaration of variables bandwidth = 1; total_bandwidth = 1/bandwidth; f = 0:.05*bandwidth:2*total_bandwidth; x=f*total_bandwidth; %Manchester Power...

  • Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y =...

    Please show the code necessary, and explanations on MATLAB. Plotting 11) Plot the function y = sin(x) from x = 0 to 21. 12) Plot the functions y = x2 z = x2 + 2x + 1 from x = 0 to 2 on the same graph. Scripts: Input and Output 13) Write a script (M-file) to read in a message at the command line using the MATLAB input function and then display the message to the Command Window using...

  • Please help with this code For the following problem write a Matlab® script file with clear...

    Please help with this code For the following problem write a Matlab® script file with clear commentary for each line of code. Your script should: Load the data in the problem as a text file. Calculate the statistics using Matlab  functions. Solicit input from the user of the reading (for example, 137 degrees as stated in the problem). In another word, the reading should not be fixed in the script and has to be entered and saved from the command window...

  • MATLAB question I need the code exactly as you would write it in MATLAB. thank you...

    MATLAB question I need the code exactly as you would write it in MATLAB. thank you 1. Consider a Gaussian solution of the traveling-wave form ψ(z,t)-exp(-a(z-vt)2). The parameter values are a 1, 2. (a) Explain the physical meaning of these parameters (eg. what would happen if we took a = 10 instead?) Determine the direction of propagation of this solution: Is it traweling to the left or to the right? (2pts) (b) Write a Matlab code to plot the Gaussian...

  • I need help solving these questions,please don’t know how to solve it by using matlab.!

    i need help solving these questions,please don’t know how to solve it by using matlab.! Solve the following questions Ol: You are required to develop a script to calculate the volume of a pyramid, which is 1/3 *base *height, where the base is length *width. Prompt the user to enter values for the length, width, and height, and then calculate the volume of the pyramid. When the user enters each value, he or she will then also be prompted to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT