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

How to do the follwoing in MATLAB For the following two matrices, 7:14 10 12|Z=[

ID: 1766746 • Letter: H

Question

How to do the follwoing in MATLAB

For the following two matrices, 7:14 10 12|Z=[10 22 5 13] 7 21 27 Define Y and Z, and find the index numbers of the elements in Y and Z that contain values greater than 10 and less than 40 using a single index notation. Find the values in each matrix of Y and Z that are greater than 10 and less than 40 using a single indices found in the part a. Display the results as shown below*: values of elements in Y are 21 12 27 values of elements in Z are 22 13 a. b. *Use disp() and num2str() commands to display the results. Find the row and column numbers for the elements in matrix Y that contain values greater than 10 and less than 40. You must display row and column numbers in each line. Repeat c. for a row vector Z. c. d.

Explanation / Answer

Code:-

clc
clear all
Y =[1 2 3; 4 10 12 ;7 21 27];
Z = [ 10 22 5 13];

sngl_index_Y= find(Y>10 & Y<40);
sngl_index_Z= find(Z>10 & Z<40);

disp(char(strcat ('Value of element in Y are',{' '},num2str(Y(sngl_index_Y)'))))
disp(char(strcat ('Value of element in Z are',{' '},num2str(Z(sngl_index_Z)))))

[row_y col_y]= find(Y>10 & Y<40);

y_req = [];
for k = 1:length(row_y)

y_req = [y_req, Y(row_y(k), col_y(k))];

end

[row_z col_z]= find(Z>10 & Z<40);

z_req = [];

for k = 1:length(row_z)

z_req = [z_req, Z(row_z(k), col_z(k))];

end

disp(char(strcat ('Value of element in Y are',{' '},num2str(y_req))))
disp(char(strcat ('Value of element in Z are',{' '},num2str(z_req))))


Output:-

Value of element in Y are 21 12 27
Value of element in Z are 22 13
Value of element in Y are 21 12 27
Value of element in Z are 22 13

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