Help please, this is due soon. Write a MATLAB function that takes three inputs,
ID: 3601212 • Letter: H
Question
Help please, this is due soon.
Write a MATLAB function that takes three inputs, two strings with the locations of csv files, and an integer called cap. It should return and n x m matrix of uint8s, where n x m is the dimension of the matrices contained in each csv file. You can assume they both contain matrices that are the same size. Your function should read each csv file and convert the resulting variable to uint8 format.
You will now have two n x m matrices. For your output matrix, implement the following algorithm:
For a given index, if the corresponding element of either matrix from the csv files is greater than 125, the corresponding element of your output matrix should be the value of cap. If neither element is above 125, the corresponding element of your output matrix should be the larger of the two elements minus the smaller of the two elements (or 0 if they have the same value). please write comments with your code.
Explanation / Answer
function mat=csvFile(a,b,cap)
M1=uint8(csvread(a));%matrix from csv file read in uint format
M2=uint8(csvread(b));
mat=uint8(zeros(size(M1)));%matrix initialized to be returned
for i=1:size(M1,1)%traversing rows
for j=1:size(M1,2)%traversing columns
if M1(i,j)>125||M2(i,j)>125
mat(i,j)=cap;
else
mat(i,j)=abs(M1(i,j)-M2(i,j));
end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.