How to plot from .txt file
How do I plot the 2D and mesh graphs asked for if this is the code I’m using?
%start with a right triangle of length x = 1 and y = 1
%calculate all values (hypotenuse, perimeter, and area)
%for combinations of x = 1:5 and y = 1:5
%Print all of those as a table to a .txt file
%output should look something like this
%{
x y h p a
1 1 1.4 3.41 0.5
1 2 2.24 5.24 1
…..
…..
….. etc
%}
% using the data from the table
% plot a line (2d) graph of the perimeter(x axis) vs area (y axis)
% plot a mesh (3d) graph with x, y (respectively), and h on the ‘z’ axis
x = 1
y = 1
myFile = fopen(‘myValues.txt’, ‘w’)
fprintf(myFile, "X LengthtY Lengtht Hypot LengthttPerimeterttArean")
for i = 1:5
for j = 1:5
myHypot = hValue(i,j)
myPerim = pValue(i,j)
myArea = aValue(i,j)
fprintf(myFile, string(i) + "ttt" + string(j) + "tttt" + string(myHypot) + "ttt" + string(myPerim) + "ttt" + string(myArea) + "n")
end
end
plot(myPerim,myArea)
function hValue = hValue(xValue,yValue)
hValue = sqrt(xValue.^2+yValue.^2);
end
function pValue = pValue(xValue,yValue)
pValue = (xValue + yValue + (sqrt(xValue.^2+yValue.^2)));
end
function aValue = aValue(xValue,yValue)
aValue = 0.5*xValue*yValue;
endHow do I plot the 2D and mesh graphs asked for if this is the code I’m using?
%start with a right triangle of length x = 1 and y = 1
%calculate all values (hypotenuse, perimeter, and area)
%for combinations of x = 1:5 and y = 1:5
%Print all of those as a table to a .txt file
%output should look something like this
%{
x y h p a
1 1 1.4 3.41 0.5
1 2 2.24 5.24 1
…..
…..
….. etc
%}
% using the data from the table
% plot a line (2d) graph of the perimeter(x axis) vs area (y axis)
% plot a mesh (3d) graph with x, y (respectively), and h on the ‘z’ axis
x = 1
y = 1
myFile = fopen(‘myValues.txt’, ‘w’)
fprintf(myFile, "X LengthtY Lengtht Hypot LengthttPerimeterttArean")
for i = 1:5
for j = 1:5
myHypot = hValue(i,j)
myPerim = pValue(i,j)
myArea = aValue(i,j)
fprintf(myFile, string(i) + "ttt" + string(j) + "tttt" + string(myHypot) + "ttt" + string(myPerim) + "ttt" + string(myArea) + "n")
end
end
plot(myPerim,myArea)
function hValue = hValue(xValue,yValue)
hValue = sqrt(xValue.^2+yValue.^2);
end
function pValue = pValue(xValue,yValue)
pValue = (xValue + yValue + (sqrt(xValue.^2+yValue.^2)));
end
function aValue = aValue(xValue,yValue)
aValue = 0.5*xValue*yValue;
end How do I plot the 2D and mesh graphs asked for if this is the code I’m using?
%start with a right triangle of length x = 1 and y = 1
%calculate all values (hypotenuse, perimeter, and area)
%for combinations of x = 1:5 and y = 1:5
%Print all of those as a table to a .txt file
%output should look something like this
%{
x y h p a
1 1 1.4 3.41 0.5
1 2 2.24 5.24 1
…..
…..
….. etc
%}
% using the data from the table
% plot a line (2d) graph of the perimeter(x axis) vs area (y axis)
% plot a mesh (3d) graph with x, y (respectively), and h on the ‘z’ axis
x = 1
y = 1
myFile = fopen(‘myValues.txt’, ‘w’)
fprintf(myFile, "X LengthtY Lengtht Hypot LengthttPerimeterttArean")
for i = 1:5
for j = 1:5
myHypot = hValue(i,j)
myPerim = pValue(i,j)
myArea = aValue(i,j)
fprintf(myFile, string(i) + "ttt" + string(j) + "tttt" + string(myHypot) + "ttt" + string(myPerim) + "ttt" + string(myArea) + "n")
end
end
plot(myPerim,myArea)
function hValue = hValue(xValue,yValue)
hValue = sqrt(xValue.^2+yValue.^2);
end
function pValue = pValue(xValue,yValue)
pValue = (xValue + yValue + (sqrt(xValue.^2+yValue.^2)));
end
function aValue = aValue(xValue,yValue)
aValue = 0.5*xValue*yValue;
end plots, mesh, graph, text file, matlab MATLAB Answers — New Questions