Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A fluid valve company has hired you to create a pressure conversion table for th

ID: 3811661 • Letter: A

Question

A fluid valve company has hired you to create a pressure conversion table for their employees to use. A template for the table is shown below. 1) Create a function named CreateTable that will input to the function the pressure unit header (cell array of strings) shown in the table above and a vector containing the conversion numbers (array of doubles). The function output should return the variable PTable from the function that will be a 10 times 10 cell array containing the numbers that will fill the table above. The employees would also like to save the table to a file. Create a function SaveTable which saves the table to a file using fprintf. This function inputs the cell array PTable which will save the pressure table to the file PressureTable.txt Create another function named PrintTable that will print the table to the screen/command window in a formatted way using fprintf This function will take the cellarray PTable as the input argument and have no return argument. The table should like the following output below which shows the first few lines of the sample pressure table. It looks better in Matlab. You should try to mimic this output as closely as possible. Create a function ConvertPressure which has four input arguments to the function: PTable (10 times 10 cell array), a pressure value (float, scalar) its corresponding units (string) and the units for the converted pressure (string). The output from the function is the converted pressure value (float, scalar). The function must be able to convert all of the pressure units summarized in the table above.

Explanation / Answer

unitHeader = ["kPa", "bar", "psi", "atm", "inHg", "inH2O", "torr", "mmHg", "MPa"];
convNumber = [1.000, 0.0100, 0.1450, 0.0099, 0.2953, 4.0147, 7.5005, 7.5006, 0.0010];

PTable = CreateTable(unitHeader, convNumber);
SaveTable(PTable);
PrintTable(PTable);

input = [4.32, 12, 1.9];
output = ConvertPressure(PTable, input, "bar", "atm");

function PTable = CreateTable(unitHeader, convNumber)
nItem = size(unitHeader, 2);
PTable = cell(nItem + 1);
  
PTable{1,1} = "FromTo";
  
for i = 2:nItem+1
PTable{1,i} = unitHeader(i-1);
PTable{i,1} = unitHeader(i-1);
end
  
for i = 2:nItem+1
for j = 2:nItem+1
PTable{i,j} = convNumber(j-1) / convNumber(i-1);
end
end
end

function SaveTable(PTable)
fileID = fopen('PressureTable.txt','w');
form = "%s: %s %s %s %s %s %s %s %s %s ";
fprintf(fileID, form, PTable{1,:});
  
form = "%s | %0.4f | %0.4f | %0.4f | %0.4f | %0.4f | %0.4f | %0.4f | %0.4f | %0.4f ";
[nrows, ~] = size(PTable);
  
for i = 2:nrows
fprintf(fileID, form, PTable{i, :});
end
  
end

function PrintTable(PTable)
[nrows, ncols] = size(PTable);
  
str = "FromTo : ";
for i=2:ncols
str = strcat(str, " ", PTable{1,i});
end
disp(str);
for i = 2:nrows
str = PTable{i,1};
for j = 2:ncols
str = strcat(str, " | " , num2str(PTable{i,j}));
end
disp(str);
end
end

function Value = ConvertPressure(PTable, input, givenUnit, requiredUnit)
[nrows, ncols] = size(PTable);
  
for i = 1:nrows
if strcmp(PTable{i,1}, givenUnit)
x = i;
end
if strcmp(PTable{1, i}, requiredUnit)
y = i;
end
end
  
convFactor = PTable{x, y};
sizeInput = size(input, 2);
  
Value = zeros(1, sizeInput);
  
for i = 1:sizeInput
Value(i) = input(i) * convFactor;
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote