Matlab code required
Q2. Double for loop - If/else on matrices
My Solutions:
A large matrix of random numbers from 0 to 9 will be generated in variable P as shown below.
Use a double for loop to cycle through all the elements of P. Store one of the following results based on the corresponding element in P in a variable S:
- If P < 3, then S = -1
- If 3 <= P <= 7, then S = 0
- If P > 7, then S = 1
Script:
Save
CReset
MATLAB Documentation
% Matrix of random numbers p [009 00t]tpueu[009 00]tpue[6e]tpueu=d
% Write a double for loop to check elements of p and store results in s