Wire a function in Matlab function [density] = myCalculateDensity( X ) a. INPUTS
ID: 3697358 • Letter: W
Question
Wire a function in Matlab function [density] = myCalculateDensity( X ) a. INPUTS: A 2D matrix X. For this project, each element of X will represent a pixel of bone. The higher the number, the higher the density of that little square of bone. b. FUNCTIONALITY: i. This function calculates the average density of all non-zero elements of a matrix X. c. OUTPUTS: i. density d. TEST CASE: >> A = [176.2360 171.0640 115.8960 162.4440; 207.2680 179.6840 0.0000 0.0000; 233.1280 190.0280 145.2040 146.9280; 248.6440 177.9600 181.4080 164.1680]; >> myCalculateDensity(A) ans = 178.5757Explanation / Answer
r=input('enter number of rows');
c=input('enter number of cols ');
count=0;
sum=0;
for i=1:r
for j=1:c
x(i,j)= input('enter elements into the array');
if(x(i,j)>0)
count=count+1;
end
end
end
for i=1:r
for j=1:c
sum =sum+x(i,j);
end
end
average = sum/count
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.