How to make a table and 2D graph of 3 variables?

I need to create a table where the rows are one variable and the columns are another variable, but within the table is the values of the function created by the 2 other variables. Also, from that I need to create specifically a 2D graph where the x and y are the variables and the plot itself is the function. This seems simple, but I'm just stuck. Any input will help please!

Answers (1)

I'm not sure about the "table" you want. Here's a simple example of how to define two vector values, then compute a 2D result and plot it.
x = [1:10];
y = [21:30];
[X,Y] = meshgrid(x,y);
Z = sqrt(X.^2 + Y.^2);
surf(X, Y, Z)

5 Comments

Thank you!
For the table picture something like the far left column is 3 4 5 down the left side and then 1 2 3 on the top row and then within the "connecting" rows/columns it would be for example the spot combing the first column(3) and first number in the row(1) it will say 3 for multiplying them. The next combination to the right of it would be 1*4, etc. If that isn't clear/you aren't sure how to do that that is okay.
Note that since R2016b, the meshgrid above is not needed (and prior to R2016b, bsxfun would have been more efficient):
Also note that there's no reason to enclose 1:10 in []. The [] brackets is a wasted call to horzcat which concatenates an array with nothing.
x = 1:10;
y = (21:30)'; %create y as a COLUMN vector
z = sqrt(x.^2 + y.^2); %prior to R2016b: z = sqrt(bsxfun(@plus, x.^2, y.^2));
@Nicolas, your explanation is really not clear. Please provide an example of input and desired output.
exampletable.jpg
Generate an efficiency table with eleven columns of inlet air temperature (-40, -30, … , 60°C) and 21 rows of TIT (500, 550, 600, …, 1450, 1500°C). Results should be rounded to 3 digits, e.g. .566 if actual value is .565678988.
The professor gave us this as the question. He also gave us a function of the two different temperatures that i replaced with a function of f = X*Y for the excel example. I filled in only some of the columns for the example, but they would all be filled in the real version
Ah, so this is homework.
Surely, you can figure out how to generate your output array from the help you've been given so far. You just have to change the sqrt expression in something even simpler.
I'm not sure what you mean? do you have any references on creating tables such as those?

Sign in to comment.

Asked:

on 13 Mar 2019

Commented:

on 14 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!