A file named temp.txt contains temperature information collected from a set of t
ID: 3559915 • Letter: A
Question
A file named temp.txt contains temperature information collected from a set of
thermocouples. The data in the file are shown in the table below. The first column
consists of time measurements (one for each hour of the day), and the remaining columns correspond to temperature measurements at different sensors in an industrial plant.
(a) Write a Matlab program that prints the index numbers (rows and columns) of
temperature data values greater than 85.0.
(b) Find the index numbers (rows and columns) of temperature data values less than
65.0.
(c) Find the maximum and minimum temperatures in the file and the corresponding
hour and sensor number.
(d) What percentage of the temperature readings at each sensor lies between 65.0 and
85.0?
Everything must be in Matlab!
Explanation / Answer
tem=textread('temp.txt');
N=size(tem);
% Find temperature greater than 85
fprintf('Temperature greater than 85.0 ');
match=(tem>85.00);
for i=1:N(1)
for j=2:N(2)
if match(i,j)==1
fprintf('Row= %d ; Column=%d ; Temp=%0.2f ', i,j,tem(i,j));
end
end
end
fprintf('-------------------------------------------- ');
% Find temp less than 65
fprintf('Temperature less than 65.0 ');
match=(tem<65.00);
for i=1:N(1)
for j=2:N(2)
if match(i,j)==1
fprintf('Row= %d ; Column=%d ; Temp=%0.2f ', i,j,tem(i,j));
end
end
end
fprintf('-------------------------------------------- ');
% Maximum temperature
max_tem=max(max(tem(:,2:4)),[],2);
for i=1:N(1)
for j=2:N(2)
if tem(i,j)== max_tem
fprintf('Maximum temp= %0.2f, Hour=%d, Sensor=%d ',max_tem,tem(i,1),j);
end
end
end
% Minimum temperature
min_tem=min(min(tem(:,2:4)),[],2);
for i=1:N(1)
for j=2:N(2)
if tem(i,j)== min_tem
fprintf('Minimum temp= %0.2f, Hour=%d, Sensor=%d ',min_tem,tem(i,1),j);
else
end
end
end
fprintf('-------------------------------------------- ');
% Percentage temperature for sensor 2
count=0;
for i=1:N(1)
if tem(i,2)>= 65.00 && tem(i,2)<85.00
count=count+1;
end
end
fprintf('At sensor= 2 , Percentage temperatue between 65 and 85 is= %0.2f ', count./N(1)*100);
% Percentage temperature for sensor 3
count=0;
for i=1:N(1)
if tem(i,3)>= 65.00 && tem(i,3)<85.00
count=count+1;
end
end
fprintf('At sensor= 3 , Percentage temperature between 65 and 85 is= %0.2f ', count./N(1)*100);
% Percentage temperature for sensor 4
count=0;
for i=1:N(1)
if tem(i,4)>= 65.00 && tem(i,4)<85.00
count=count+1;
end
end
fprintf('At sensor= 4 , Percentage temperature between 65 and 85 is= %0.2f ', count./N(1)*100);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.